File Handling in Python Class 12 Computer Science Important Questions

Important Questions Class 12

Students can read the important questions given below for File Handling in Python Class 12 Computer Science. All File Handling in Python Class 12 Notes and questions with solutions have been prepared based on the latest syllabus and examination guidelines issued by CBSE, NCERT and KVS. You should read all notes provided by us and Class 12 Computer Science Important Questions provided for all chapters to get better marks in examinations. Computer Science Question Bank Class 12 is available on our website for free download in PDF.

Important Questions of File Handling in Python Class 12

Very Short Answer Type Questions :

Question: What is a data file in python?
Answer: A bunch of bytes / data stores on some storage device referred by the filename.

Question: What is the difference between “w” and “a” modes?
Answer: “w” mode opens file in write mode but “a” mode opens file in append mode.

Short Answer Type Questions :

Question: Differentiate between a text file and a binary file.
Answer: A text file stores data as ASCII/UNICODE characters where as a binary file stores data in binary format (as it is stored in memory). Internal conversion is required in text file and hence slower but binary file does not need any translation and faster.

Question: Differentiate between Absolute path and relative path.
Answer: The absolute paths are from the topmost level of the directory structure. The relative paths are relative to the current working directory denoted as a dot(.) while its parent directory is denoted with two dots(..).

Question: What does stdin, stdout represent?
Answer: stdin represent standard input device and stdout represent standard output device which are represented as files.

Application Based Questions :

Question: Write a python code to find the size of the file in bytes, number of lines and number of words.
Answer: # reading data from a file and find size, lines, words
f=open(‘Lines.txt’,’r’) )
print(‘size of file n bytes’,size)
L=f.readlines( )
word=L.split( )
print(‘Number of lines ’,len(L))
print(‘Number of words ’,len(word))
f.close( )

Question: Write code to print just the last line of a text file “data.txt”.
Answer: fin=open(“data.txt”,”r”)
print(“Last line = “, lineList[-1])