Quiz on File Handling in Python

An illustration of a computer screen displaying code with Python files and folders around it, colorful and engaging, representing file handling in Python programming.

File Handling Mastery Quiz

Test your knowledge on file handling in Python with our engaging quiz! Dive into the core concepts of reading and writing files, exploring various modes, and understanding binary operations.

Whether you are a beginner or looking to refresh your skills, this quiz will help you:

  • Identify the correct file handling methods
  • Understand file modes
  • Enhance your Python programming skills
10 Questions2 MinutesCreated by WritingCode102
1. Which of the following functions do you use to write data in the binary format?
Write
Output
Dump
Send
2. Which of the following command is used to open a file “c:\temp.txt” for reading in binary format only?
A. outfile = open(“c:\temp.txt”, “r”)
B. outfile = open(“c:\\temp.txt”, “rb”)
C. outfile = open(“c:\temp.txt”, “r+”)
D. outfile = open(“c:\\temp.txt”, “rb+”)
3. What does the method returns?
A. str
B. A list of lines
C. List of single characters
D. List of integers
4. Which of the following commands can be used to read the entire contents of a file as a string using the file object ?
A. tmpfile.read(n)
B. tmpfile.read()
C. tmpfile.readline()
D. tmpfile.readlines()
5. Which of the following statements are true regarding the opening modes of a file? Select whatever is true.
A. When you open a file for reading, if the file does not exist, an error occurs.
B. When you open a file for writing, if the file does not exist, an error occurs.
C. When you open a file for reading, if the file does not exist, the program will open an empty file.
D. When you open a file for writing, if the file does not exist, a new file is created.
E. When you open a file for writing, if the file exists, the existing file is overwritten with the new file.
6. Which of the following file mode will refer to the writing and reading both BINARY file?
Wb
Wb+
W+
W
7. If we do not specify file mode while opening a file, the file will open in .............mode
Read
Write
Append
Will give an error
8. To read the entire remaining contents of the file as a string from a file object infile, we use ____________
A) infile.read(2)
B) infile.read()
C) infile.readline()
D) infile.readlines()
9. What is the output:
Compilation error
Run time error
No output
Flushes the file when closing them
10. What is the output of the following print() function print(sep='--', 'Ben', 25, 'California')
A. Syntax Error
B. Ben–25–California
C. Ben 25 California
D. Ben–25 California
{"name":"Quiz on File Handling in Python", "url":"https://www.quiz-maker.com/QPREVIEW","txt":"Test your knowledge on file handling in Python with our engaging quiz! Dive into the core concepts of reading and writing files, exploring various modes, and understanding binary operations.Whether you are a beginner or looking to refresh your skills, this quiz will help you:Identify the correct file handling methodsUnderstand file modesEnhance your Python programming skills","img":"https:/images/course5.png"}
Powered by: Quiz Maker