WorksheetsFile Handling in Python Quiz
Total questions: 15
Worksheet time: 11mins
What is the primary purpose of file handling in Python?
To design user interfaces
To create different file formats
To read, write, and manage data in files
To store values in python
What does the 'r' mode do when opening a file?
Creates a new file
Opens a file for reading
opens a file for appending
Writes data to a file
What happens when you open a file in 'w' mode?
It reads the file content
It appends to the file
It overwrites the existing content
It creates a new file without overwriting
Which method reads the entire content of a file?
read(entire)
readall()
read()
readline()
What does the 'a' mode do when opening a file?
Reads the file content
Appends data to the end of the file
Appends data to the beginning of the file
Overwrites existing content
A student first creates a file called "notes.txt" and then writes the code given and runs, but notices no output.
What could be the problem?
No problem, the outprint is not just printed.
The student has not added \n at the end
Reading mode 'r' doesn’t allow writing, so values are not added
The file is not closed properly.
What is the result of using 'x' mode on an existing file?
It creates a new file and returns an error
It reads the file content
It overwrites the file
It appends to the file
A file is necessary to store values for repeated use.
What does the 'readline()' method do?
Reads the entire file line by line
Reads one line at a time
Reads a specific number of characters
reads the type of the file
What happens if you try to open a file in 'r' mode that does not exist?
It opens an empty file
It returns an error
It creates a new file
Does nothing
Which of the following is NOT a basic file operation?
Execute
Update
Read
Create
We can directly write values into the file without opening it first.
The 'f' in f = open("demofile.txt", "x") is:
function
method
control statement
variable/object
If you just write,
f = open("demofile.txt")
the mode is not mentioned. What is the default mode in which the "demofile.txt" is opened?
read
write
create
append
Imagine you are maintaining a log of babies born in 2025. You need to submit the list to the National Statistics Bureau by the end of 2025. Which mode (w or a) should you use?
(a)
