Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

File Handling in Python Quiz

Total questions: 15

Worksheet time: 11mins

Name
Class
Date
1.

What is the primary purpose of file handling in Python?

a)

To design user interfaces

b)

To create different file formats

c)

To read, write, and manage data in files

d)

To store values in python

2.

What does the 'r' mode do when opening a file?

a)

Creates a new file

b)

Opens a file for reading

c)

opens a file for appending

d)

Writes data to a file

3.

What happens when you open a file in 'w' mode?

a)

It reads the file content

b)

It appends to the file

c)

It overwrites the existing content

d)

It creates a new file without overwriting

4.

Which method reads the entire content of a file?

a)

read(entire)

b)

readall()

c)

read()

d)

readline()

5.

What does the 'a' mode do when opening a file?

a)

Reads the file content

b)

Appends data to the end of the file

c)

Appends data to the beginning of the file

d)

Overwrites existing content

6.

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?

a)

No problem, the outprint is not just printed.

b)

The student has not added \n at the end

c)

Reading mode 'r' doesn’t allow writing, so values are not added

d)

The file is not closed properly.

7.

What is the result of using 'x' mode on an existing file?

a)

It creates a new file and returns an error

b)

It reads the file content

c)

It overwrites the file

d)

It appends to the file

8.

A file is necessary to store values for repeated use.

a)
True
b)
False
9.

What does the 'readline()' method do?

a)

Reads the entire file line by line

b)

Reads one line at a time

c)

Reads a specific number of characters

d)

reads the type of the file

10.

What happens if you try to open a file in 'r' mode that does not exist?

a)

It opens an empty file

b)

It returns an error

c)

It creates a new file

d)

Does nothing

11.

Which of the following is NOT a basic file operation?

a)

Execute

b)

Update

c)

Read

d)

Create

12.

We can directly write values into the file without opening it first.

a)
True
b)
False
13.

The 'f' in f = open("demofile.txt", "x") is:

a)

function

b)

method

c)

control statement

d)

variable/object

14.

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?

a)

read

b)

write

c)

create

d)

append

15.

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)