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

1. Which function is used to open a file in Python?

  • file_open()
  • open()
  • read_file()
  • file()
Show Answer Report

2. Which mode opens a file for reading only?

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

3. Which mode creates a new file for writing and returns error if file exists?

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

4. Which method reads the entire content of a file as a string?

  • readline()
  • readall()
  • read()
  • get()
Show Answer Report

5. Which method reads one line from a file?

  • read()
  • readline()
  • nextline()
  • getline()
Show Answer Report

6. Which method returns all lines in a file as a list?

  • read()
  • readlines()
  • getlines()
  • lines()
Show Answer Report

7. Which mode opens a file for both reading and writing?

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

8. What is the correct way to close a file in Python?

  • file.close()
  • close(file)
  • file->close()
  • close.file()
Show Answer Report

9. Which statement automatically closes a file after usage?

  • for
  • while
  • with
  • using
Show Answer Report

10. Which method writes a string to a file?

  • writeline()
  • put()
  • write()
  • output()
Show Answer Report
Questions and Answers for Competitive Exams Various Entrance Test