Reading and Writing Files Questions and Answers
Practice ModeShowing 10 of 25 questions
Q11
Which method writes a list of strings to a file?
Answer: Option B
Explanation: The writelines() method takes a list of strings and writes them to the file.
Q12
What does "w" mode do if the file already exists?
Answer: Option C
Explanation: "w" mode truncates (erases) the file if it already exists, then opens it for writing.
Q13
Which mode appends to a file without truncating it?
Answer: Option C
Explanation: "a" mode opens a file for appending and creates the file if it doesn't exist.
Q14
What is the default mode when opening a file with open()?
Answer: Option B
Explanation: If no mode is specified, open() defaults to "r" (read mode).
Q15
Which method moves the file pointer to a specific position?
Answer: Option C
Explanation: The seek() method moves the file pointer to the specified byte position.
Q16
Which method returns the current file pointer position?
Answer: Option C
Explanation: The tell() method returns the current position of the file pointer.
Q17
What does seek(0) do?
Answer: Option B
Explanation: seek(0) moves the file pointer to the beginning of the file.
Q18
Which mode opens a file for binary reading?
Answer: Option C
Explanation: "rb" mode opens a file for reading in binary mode.
Q19
Which method flushes the internal buffer?
Answer: Option B
Explanation: The flush() method clears the internal buffer and writes data to the file immediately.
Q20
What is the correct syntax for opening a file using with statement?
Answer: Option A
Explanation: The with statement ensures proper resource management and automatic file closing.