wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

python file handling

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

Select the statement to open a file named MYDATA.dat in read binary mode. Let the file object name be myfile.

a)

myfile=open("MYDATA.dat","rb")

b)

myfile=open("MYDATA.dat","r+")

c)

myfile=open("MYDATA.dat","r")

2.

Mode in the following program to open file for writing in a mode where new data will be added at the end of old data

file =open("poem.txt","__")

a)

r

b)

w

c)

a

d)

r+

3.

Choose the correct statement to close a file stream named myfile:

a)

myfile.terminate()

b)

myfile.end()

c)

myfile.close()

d)

myfile.remove()

4.

What will be the ouput -

f=open('abc.txt','w')

x=f.read()

f.close()

print(x)

a)

Error(not readable)

b)

Error(not writable)

c)

It will read all the data of the file.

d)

none

5.

What will be the output-

f=open('abc.txt','a')

text="xyz"

f.write(text)

f.close()

a)

Writing into the file without erasing old content

b)

Writing into the file by erasing old content

c)

reading from the file without erasing old content

d)

reading from the file by erasing old content

6.

Which function is used to write multiple lines in text file?

a)

write()

b)

writelines()

c)

lines()

d)

print()

7.

Which statement(s) is/are true to open a binary file "Record.dat" for reading and writing ?

a)

file =open("Record.dat","wb")

b)

file =open("Record.dat","rb")

c)

file =open("Record.dat","ab")

d)

file =open("Record.dat","rb+")

8.

The readlines() method returns

a)

a. str

b)

b. a list of lines

c)

c. a list of single characters

d)

d. a list of integers

9.

An absolute path name begins at the

a)

leaf

b)

stem

c)

root

d)

current directory

10.

What will be the output of the following Python code?

a)

True

b)

False

c)

None

d)

error