wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Data file Handling in Python

Total questions: 36

Worksheet time: 17mins

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.

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

a)

myfile.terminate()

b)

myfile.end()

c)

myfile.close()

d)

myfile.remove()

5.

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

6.

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

7.

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

a)

write()

b)

writelines()

c)

lines()

d)

print()

8.

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

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.

An absolute path name begins at the

a)

leaf

b)

stem

c)

root

d)

current directory

11.

What will be the output of the following Python code?

a)

True

b)

False

c)

None

d)

error

12.

Which file execute faster?

a)

Text file

b)

Binary file

c)

CSV file

13.

Mode used for reading and writing in binary file

a)

wb

b)

w

c)

wb+

d)

w+

14.

Function used to write data in binary format

a)

write()

b)

output()

c)

load()

d)

dump()

15.

The type of operation possible in an opened file is governed by

a)

File Object

b)

File Mode

c)

File Path

d)

open() Method

16.

Module used to read and write into binary files

a)

dump

b)

load

c)

pickle

d)

open

17.

Function returns the current position of file pointer in the file

a)

tell()

b)

seek()

c)

read()

d)

flush()

18.

Which of the following is not a valid attribute of a file object (fp)?

a)

fp.name

b)

fp.closed

c)

fp.size

d)

fp.mode

19.

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

20.

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

a)

write()

b)

writelines()

c)

lines()

d)

print()

21.

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

22.

An absolute path name begins at the

a)

leaf

b)

stem

c)

root

d)

current directory

23.

Which file is not binary file?

a)

student.mp4

b)

student.jpeg

c)

student.csv

d)

student.exe

24.

Which is not a text file?

a)

data.txt

b)

data.csv

c)

data.rft

d)

data.mp3

25.

Which function read single line at a time?

a)

read()

b)

read(n)

c)

readline()

d)

readlines()

26.

Which memory is volatile memory?

a)

RAM

b)

Hard Disk

c)

CD

d)

Pen drive

27.

Where files are store permanently?

a)

RAM

b)

Hard Disk

c)

Cache memory

d)

None of these

28.

Which are the text editor software?

a)

Notepad

b)

Wordpad

c)

MS word

d)

PPT

29.

In our computer all software and files are store in

a)

DVD

b)

CD

c)

RAM

d)

Hard Disk

30.

By default python program save in which drive?

a)

D Drive

b)

C Drive

c)

E Drive

d)

F Drive

31.
Which of the following is not a method of opening files?
a)
Replace
b)
Append
c)
Write
d)
Read
32.
Appending to a file means adding extra data into the file.
a)
True
b)
False
33.
What is the last action that must be performed on a file?
a)
Close
b)
Save
c)
End
d)
Write
34.
What is the data type of data read from a file?
a)
String
b)
Integer
c)
Real
d)
Boolean
35.

How do Python represent a Complex number with real part (3) and imaginary part ( -2.5)

a)

3+2.5i

b)

3-2.5i

c)

3+2.5j

d)

3-2.5j

36.

Do you think the CS Online class is interesting?

a)

yes

b)

no

c)

may be

d)

no comments