The Wayback Machine - https://web.archive.org/web/20250407113612/https://www.geeksforgeeks.org/quizzes/python-file-handling-quiz/

Python File handling quiz

Last Updated :
Discuss
Comments

Question 1

What is file handling in Python?

  • Managing folders

  • Reading and writing file

  • Controlling system files

  • Handling exceptions in files

Question 2

Which function is used to open a file in Python?

  • open_file()

  • read_file()

  • file_open()

  • open()

Question 3

Which method is used to read the entire content of a file as a string?

  • read()

  • read_all()

  • read_full()

  • readfile()

Question 4

What is the purpose of the 'rb' mode in file opening?

  •  Read binary

  •  Replace binary

  • Read and backup

  • Rename binary

Question 5

What is the purpose of the 'a' mode in file opening?

  • Append

  • Add

  • Access

  • Assign

Question 6

How can you read the first five characters of a file in Python?

  • file.read(5)

  • read(file, 5)

  • read_first(file, 5)

  • file.read_first(5)

Question 7

How do you check if a file exists before opening it in Python?

  • check_file_existence()

  • file_exists()

  • os.path.exists()

  • verify_file()

Question 8

What is the purpose of the 'with' statement in file handling?

  • It creates a new file

  • It automatically closes the file

  • It appends data to a file

  • It reads the entire file at once

Question 9

How do you read a file line by line in Python?

  • read_all_lines()

  • file.read_line()

  • readlines()

  • read_line(file)

Question 10

How can you write data to a file without overwriting its existing content in Python?

  • file.write_data()

  • write_file()

  • file.write_append()

  • file.write('a')

"This course is very well structured and easy to learn. Anyone with zero experience of data science, python or ML can learn from this. This course makes things so easy that anybody can learn on their own. It's helping me a lot. Thanks for creating such a great course."-  Ayushi Jain | Placed at Microsoft

Now's your chance to unlock high-earning job opportunities as a Data Scientist! Join our Complete Machine Learning & Data Science Program and get a 360-degree learning experience mentored by industry experts.

Get hands on practice with 40+ Industry Projects, regular doubt solving sessions, and much more. Register for the Program today!

There are 25 questions to complete.

Take a part in the ongoing discussion