WORKSHEET
Worksheet No. 002 Date: 13/09/25
Class: XII Subject: Computer Science
Topic/Chapter: Data File Handling
Part A: Text File Handling
1. Which mode is used to read a text file?
a) 'w' b) 'a' c) 'r' d) 'x'
2. Which function reads one line at a time from a file?
a) read() b) readline() c) readlines() d) readchar()
3. What happens if you open a file in write mode ('w') and it already exists?
a) Appends data at the end b) Deletes the existing file content c) Gives
an error d) Opens in read
read-only mode
4. Which function is used to close a file in Python?
a) end() b) exit() c) close() d) stop()
Part B: Binary File Handling
5. Which module is used for binary file handling in Python?
a) csv b) picklee c) json d) struct
6. Which of the following writes Python objects into a binary file?
a) pickle.load() b) pickle.write() c) pickle.dump() d) pickle.save()
7. To read objects from a binary file, we use:
a) pickle.dump() b) pickle.read(
pickle.read()) c) pickle.load() d) pickle.open()
8. Which file mode is correct for writing into a binary file?
a) 'r' b) 'wb' c) 'w' d) 'rb'
Part C: CSV File Handling
9. Which Python module is used to handle CSV files?
a) json b) os c) csv d) pickle
10. The default delimiter used in CSV files is:
a) ; b) , c) : d) |
11. Which function writes a single row into a CSV file?
a) writerow() b) writerows() c) writeline() d) write()
12. Which function reads the data of a CSV file line by line as a list?
a) csv.writer() b) csv.reader() c) csv.read() d) csv.open()
Part D: Output-Based MCQs
13. What will be the output of the following code?
f = open("test.txt", "w")
f.write("Python\nFile\nHandling")
f.close()
f = open("test.txt", "r")
print(f.readline())
f.close()
a) Python b) File c) Python File Handling d) Error
14. What will be the output?
import pickle
f = open("data.dat","wb")
pickle.dump([1,2,3], f)
f.close()
f = open("data.dat","rb")
print(pickle.load(f))
f.close()
a) [1, 2, 3] b) 123 c) Error d) None
15. Suppose we have a student.csv with following data, What will the following
code output?
RollNo,Name,Marks
101,Riya,85
102,Aarav,92
import csv
f = open("student.csv","r")
r = csv.reader(f)
for row in r:
print(row)
f.close()
a) [['RollNo','Name','Marks'],['101','Riya','85'],['102','Aarav','92']]
b) ['RollNo','Name','Marks'] ['101','Riya','85'] ['102','Aarav','92']
c) Error
d) None