Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Python- Text file handling Quiz 2

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

Select the statement to open a file named MYDATA.txt in read and write 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.

What will be the output of the following Python code?

a)

True

b)

False

c)

None

d)

error

8.

An absolute path name begins at the

a)

leaf

b)

stem

c)

root

d)

current directory

9.

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

10.

Which statement is true to open a binary file "Record.txt" for writing and reading ?

a)

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

b)

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

c)

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

d)

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