File Handling in Python Class 12 Computer Science Exam Questions

Exam Questions Class 12

Please refer to Computer Science For File Handling in Python Class 12 Computer Science Exam Questions provided below. These questions and answers for Class 12 Computer Science have been designed based on the past trend of questions and important topics in your class 12 Computer Science books. You should go through all Class 12 Computer Science Important Questions provided by our teachers which will help you to get more marks in upcoming exams.

Class 12 Computer Science Exam Questions File Handling in Python

Very Short Answer Type Questions :

Question. One row of CSV file can be considered as _______ in terms of database
Answer: Record

Question. The writerow() function is a part of _________ module.
Answer: CSV

Question. A _____ function allows to write a single record into each row in CSV file.
Answer: writerow()

Question. Which of the following is not a function of csv module? 1. readline() 2. writerow() 3. reader() 4. writer()
Answer: readline()

Question. CSV module allows to write multiple rows using ____________ function.
Answer: writerrows()

Question. Write the full form of CSV
Answer: Comma Separated value

Question. Write the functions required to handle CSV files.
Answer: To handle CSV files following function required:
1. Open()
2. reader()
3. writer()
4. writerow()
5. close()

Question. The default line terminator is \n in csv file.
Answer: True

Question. A _________ is a file format which stores records separated by comma.
Answer: CSV

Question. Write to ways to import a csv module.
Answer: 1. import csv 2. from csv import *

Short Answer Type Questions :

Question. Write a python program to copy file1.txt into file2.txt 

Question. Which of the following function returns a list datatype
C) d=f.readline()
D) d=f.readlines()
Answer: f.readlines()

Question. Write a single loop to display all the contens of a text file file1.txt after removing leading and trailing WHITESPACES
for line in open(“file1.txt”):

Question. Observe the following code and answer the follow
(i)what type of file is mydata
(ii) Fill in the blank1 with statement to write “abc” in the file “mydata”
i) Text file
ii) f1.write(“abc”)

Question. Write a method in python to write multiple lines of text contents into a text file myfile.txt
def write1():
f = open(“myfile.txt”,”w”)
while True:
line = input(“Enter line”)
choice = input(“Are there more lines”)
if choice == “N”:

Question. What would be the data types of variables data in following statements?
i) )
iii) Data=f.readline()
iv) Data=f.readlines()
Answer: a) string b)string c)string d)list

Question. A given text file data.txt contains :
Line 4
What would be the output of following code?
Line 6
Line 4

Question. In which of the following file modes the existing data of the file will not be lost?
i) rb
ii) w
iii) a+b
iv) wb+
v) r+
vi) ab
vii) w+b
ix) w+
Answer: ab and a+b mode

Question. A text file “Quotes.Txt” has the following data written in it: Living a life you can be proud of Doing your best Spending your time with people and activities that are important to you Standing up for things that are right even when it’s hard
Becoming the best version of you Write a user defined function to display the total number of words present in the file.
def countwords():
S=open(“Mydata”, “r”)
count=0 for
I in z:
print(“Total number of words”,count)