wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

file handling

Total questions: 12

Worksheet time: 6mins

Name
Class
Date
1.

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+

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.

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

4.

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

5.

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

a)

write()

b)

writelines()

c)

lines()

d)

print()

6.

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+")

7.

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

8.

An absolute path name begins at the

a)

leaf

b)

stem

c)

root

d)

current directory

9.

What will be the output of the following Python code?

a)

True

b)

False

c)

None

d)

error

10.

See the following code snippet and fill in the blank with appropriate statement

(a)  

11.

Fill in the blank with appropriate statement.

(a)  

12.

which function is used to read records from a binary file?

a)

pickle.load(f)

b)

pickle.read()

c)

pickle.open()

d)

pickle.dump(l,f)