Reading and Writing Files Questions and Answers
Practice ModeShowing 10 of 25 questions
Q21
Which character is used to specify a new line when writing to files?
Answer: Option B
Explanation: \\n is the escape sequence for a new line in Python strings.
Q22
What does readline() return when end of file is reached?
Answer: Option B
Explanation: readline() returns an empty string when it reaches the end of the file.
Q23
Which mode allows reading and writing at the end of file?
Answer: Option C
Explanation: "a+" mode opens a file for both reading and writing, with writing starting at the end.
Q24
What is the purpose of file object's closed attribute?
Answer: Option B
Explanation: The closed attribute returns True if the file is closed, False otherwise.
Q25
Which method is used to check if file pointer is at end of file?
Answer: Option D
Explanation: While Python doesn't have a direct EOF method, readline() returning empty string indicates EOF.