Python File Handling
- Class 12 Computer Science File Handling in Python MCQs Set 1
- Class 12 Computer Science File Handling in Python MCQs Set 2
- Class 12 Computer Science File Handling in Python MCQs Set 3
- Class 12 Computer Science File Handling in Python MCQs Set 4
- Class 12 Computer Science File Handling in Python MCQs Set 5
- Class 12 Computer Science File Handling in Python MCQs Set 6
- Class 12 Computer Science File Handling in Python MCQs Set 7
- Class 12 Computer Science File Handling in Python MCQs Set 8
- Class 12 Computer Science File Handling in Python MCQs Set 9
File Handling in Python MCQ’s Set – 8
Multiple Choice Questions
Directions (Question Number 141 to 143) :
Sumit want to write a list in file “test.dat” file. He has written some codes, but it is not complete. Complete these statements. Code is given below.
import pickle as _____ #statement 1
letter = ['a','b','c','d']
with open('test.dat','____') as file: #statement 2
pkl.dump(letter,____) #statement 3
141. Write the valid alias name of pickle module in #statement 1 ?
a) pk
b) p
c) pkl
d) pickl
142. Fill in the blank in #statement 2 to write the proper file opening mode?
a) wb
b) a
c) r
d) w
143. Fill in the blank in #statement 3 to write the content of list to the binary file ‘test.dat’?
a) pkl.dump(letter)
b) pkl.dump(letter, file)
c) pkl.dump(letter, file_object)
d) dump.pkl(letter, file)
144. Which one is the valid difference between open() and with open() statement?
a) open() close the file automatically but with open() does not close the file automatically.
b) open() does not close the file automatically, but with open() close the file automatically.
c) open() and with open() both will close the file automatically.
d) None of these
Directions (Question Number 145 to 147) :
Riya want to write content of a dictionary in a binary file “result.dat” file. She has written some codes, but it is not working. Complete these statements. Code is given below.
import ______ #statement 1
fa_result {'amrit':50, 'sumit':45, 'tanmay':50}
with open('______','____') as file: #statement 2
_____________________ #statement 3
145. Write the valid import statement in #statement 1 ?
a) import pkl
b) import module pickle
c) import pickle
d) None of these
146. Fill in the blank in #statement 2, to open a binary file ‘result.dat’ to write dictionary.
a) with open(result.dat, wb) as file:
b) with open(‘result.dat’ , ‘wb’) as file:
c) with open(‘result.dat’, wb) as file:
d) None of these
147. Fill in the blank in #statement 3, to write the content of dictionary fa_result to the binary file ‘result.dat’?
a) pickle.dump(fa_result, file)
b) pkl.dump(fa_result, file)
c) pickle.dump(fa_result)
d) pickle.dump(file)
Directions (Question Number 148 to 151) :
Sumit want to read the content from a binary file “test.dat” as a list and print the result as list. He has written some codes, but it is not complete. Complete these statements. Code is given below.
import _______________ #statement 1
letter = []
with open('________','____') as file: #statement 2
_____________________ #statement 3
print(________) #statement 4
148. Write the statement to import the proper module in #statement 1 ?
a) import pi
b) import binaryfile
c) import pkl
d) import pickle
149. Fill in the blank in #statement 2, to open the binary file for reading
a) with (‘test.dat’, ‘wb’)
b) with open(‘test.dat’, ‘r’) as file:
c) with open(‘test.dat’, ‘rb’) as file:
d) with open(‘test.dat’, ‘wb’) as file:
150. Fill in the blank in #statement 3, to read a list from a binary file.
a) pickle.load(letter, file)
b) file = pickle.load(letter)
c) letter = load(file)
d) letter = pickle.load(file)
151. Fill in the blank in #statement 4, to display the value of list letter.
a) print(letter[0])
b) print(letter)
c) print letter
d) None of these
Directions (Question Number 152 to 155) :
Riya want to read a binary file named “result.dat” and want to read data and store in a diction. She has written some codes, but it is not working. Complete these statements. Code is given below.
import _______________ #statement 1
info = {}
with open('________','____') as file: #statement 2
_____________________ #statement 3
print(________) #statement 4
152. Write the statement to import the proper module in #statement 1 ?
a) import pi
b) import binaryfile
c) import pkl
d) import pickle
153. Fill in the blank in #statement 2, to open the binary file for reading
a) with (‘result.dat’, ‘wb’)
b) with open(‘result.dat’, ‘r’) as file:
c) with open(‘result.dat’, ‘rb’) as file:
d) with open(‘result.dat’, ‘wb’) as file:
154. Fill in the blank in #statement 3, to read a list from a binary file.
a) pickle.load(info, file)
b) file = pickle.load(info)
c) info = load(file)
d) info = pickle.load(file)
155. Fill in the blank in #statement 4, to display the value of list letter.
a) print(info[‘amit’])
b) print(info)
c) print info
d) None of these
156. “wb” mode in file handling also can be written as _____
a) w+b
b) w*b
c) w/b
d) None of these
157. Mode used for reading from pickle file is ________.
a) br
b) r*b
c) rb
d) None of these
158. When file is opened as “with open” then file is ___________ automatically..
a) open
b) read
c) write
d) close
Directions (Question Number 159 to 160) :
Define the function store_data(record) in python to write the content in a pickled file member.dat
import pickle
def store_data(record):
fileObject = open('________','____')#statement 1
pickle.______(_______, ________) #statement 2
piFile.close()
159. Write the statement to open the file to write data in #statement 1 ?
a) fileObject = open(‘member.dat’)
b) fileObject = open(‘member.dat’, ‘w’)
c) fileObject = open(‘member.dat’, ‘wb’)
d) None of these
160. Fill in the blank in #statement 2, to write record in the binary file.
a) pickle.dump(record, fileObject)
b) pickle.dump(‘record’, ‘fileObject’)
c) pickle.dump(fileObject, record)
d) None of these
Python File Handling (MCQ’s)
- Class 12 Computer Science File Handling in Python MCQs Set 1
- Class 12 Computer Science File Handling in Python MCQs Set 2
- Class 12 Computer Science File Handling in Python MCQs Set 3
- Class 12 Computer Science File Handling in Python MCQs Set 4
- Class 12 Computer Science File Handling in Python MCQs Set 5
- Class 12 Computer Science File Handling in Python MCQs Set 6
- Class 12 Computer Science File Handling in Python MCQs Set 7
- Class 12 Computer Science File Handling in Python MCQs Set 8
- Class 12 Computer Science File Handling in Python MCQs Set 9
Python Revision Tour – Multiple Choice Questions (MCQ’s)
- Class 12 Computer Science MCQs Python Revision Tour Set – 1
- Class 12 Computer Science MCQs Python Revision Tour Set – 2
Python Functions – Working with Functions (MCQ’s)
- Class 12 Computer Science Python Functions – Working with Functions MCQs Set – 1
- Class 12 Computer Science Python Functions – Working with Functions MCQs Set – 2
- Class 12 Computer Science Python Functions – Working with Functions MCQs Set – 3
- Class 12 Computer Science Python Functions – Working with Functions MCQs Set – 4
- Class 12 Computer Science Python Functions – Working with Functions MCQs Set – 5
- Class 12 Computer Science Python Functions – Working with Functions MCQs Set – 6
Thanks for visiting. Online Classes are available.