Reading and Writing Files Questions and Answers

Practice Mode
Showing 10 of 25 questions
Q21
Which character is used to specify a new line when writing to files?
  • A /n
  • B \\n
  • C newline
  • D nl
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?
  • A None
  • B Empty string
  • C False
  • D EOF
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?
  • A "r+"
  • B "w+"
  • C "a+"
  • D "x+"
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?
  • A Closes the file
  • B Checks if file is closed
  • C Opens the file
  • D Locks the file
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?
  • A eof()
  • B check_eof()
  • C feof()
  • D No direct method
Answer: Option D
Explanation: While Python doesn't have a direct EOF method, readline() returning empty string indicates EOF.
Questions and Answers for Competitive Exams Various Entrance Test