Reading and Writing Files Questions and Answers

Take Exam

Python Programming - Reading and Writing Files Questions with Answers help learners understand how to handle data in text or binary formats. These Python File Handling Questions are important for TCS, Infosys, and Bank PO exams to master file input and output operations

Reading and Writing Files

Showing 10 of 25 questions

11. Which method writes a list of strings to a file?

  • write()
  • writelines()
  • write_list()
  • putlines()
Show Answer Report

12. What does "w" mode do if the file already exists?

  • Appends to it
  • Throws an error
  • Truncates the file
  • Opens in read-only
Show Answer Report

13. Which mode appends to a file without truncating it?

  • "w"
  • "r"
  • "a"
  • "x"
Show Answer Report

14. What is the default mode when opening a file with open()?

  • "w"
  • "r"
  • "a"
  • "x"
Show Answer Report

15. Which method moves the file pointer to a specific position?

  • move()
  • position()
  • seek()
  • goto()
Show Answer Report

16. Which method returns the current file pointer position?

  • position()
  • current()
  • tell()
  • where()
Show Answer Report

17. What does seek(0) do?

  • Moves to end of file
  • Moves to beginning
  • Moves 0 bytes forward
  • Closes the file
Show Answer Report

18. Which mode opens a file for binary reading?

  • "r"
  • "br"
  • "rb"
  • "binary"
Show Answer Report

19. Which method flushes the internal buffer?

  • clear()
  • flush()
  • clean()
  • buffer()
Show Answer Report

20. What is the correct syntax for opening a file using with statement?

  • with open(file) as f:
  • with open file as f:
  • open(file) with f:
  • using open(file) as f:
Show Answer Report
Questions and Answers for Competitive Exams Various Entrance Test