Question 1 of 25
Hints left: 3
Q1
What is the purpose of the tell() method in file handling?
Q2
What is the purpose of the with statement in file handling?
Q3
What is the purpose of the write() method in file handling?
Q4
What is the output of the following code: with open('data.txt', 'w') as file: file.write('Hello, world!')
Q5
What is the output of the following code: file = open('data.txt', 'r') content = file.read() print(content)
Q6
How can you write data to a file in Python?
Q7
How can you close a file in Python?
Q8
To read two characters from a file object infile, we use . . . . . . . .
Q9
Which is/are the basic I/O connections in file?
Q10
How can you create a new file in Python if it doesn't exist?
Q11
What is the use of "a" in file handling?
Q12
What will be the output of the following code: with open('data.txt', 'r') as file: lines = file.readlines() print(len(lines))
Q13
What is the purpose of the seek() method in file handling?
Q14
Which of the following statements are true?
Q15
To open a file c:\scores.txt for appending data, we use . . . . . . . .
Q16
Correct syntax of file.writelines() is?
Q17
What will be the output of the following Python code? w = re.compile('[A-Za-z]+') w.findall('It will rain today')
Q18
To open a file c:\scores.txt for reading, we use . . . . . . . .
Q19
What is the output of the following code: with open('data.txt', 'a') as file: file.write('Appended line.') with open('data.txt', 'r') as file: content = file.read() print(content)
Q20
To open a file c:\scores.txt for writing, we use . . . . . . . .
Q21
How can you read the entire contents of a file line by line in Python?
Q22
How can you read a single line from a file in Python?
Q23
How do you open a file named data.txt in read mode in Python?
Q24
Choose the function whose output can be: <_sre.SRE_Match object; span=(4, 8), match='aaaa'>.
Q25
What does the read() method of a file object do?