CBSE Class 12 Computer Science Text File MCQs

Practice CBSE Class 12 Computer Science Text File MCQs provided below. The MCQ Questions for Class 12 Text File Computer Science with answers and follow the latest CBSE/ NCERT and KVS patterns. Refer to more Chapter-wise MCQs for CBSE Class 12 Computer Science and also download more latest study material for all subjects

MCQ for Class 12 Computer Science Text File

Class 12 Computer Science students should review the 50 questions and answers to strengthen understanding of core concepts in Text File

Text File MCQ Questions Class 12 Computer Science with Answers

Question. Which of the following command is used to open a file “c:\temp.txt” in read-mode only?
a) infile = open(“c:\temp.txt”, “r”)
b) infile = open(“c:\\temp.txt”, “r”)
c) infile = open(file = “c:\temp.txt”, “r+”)
d) infile = open(file = “c:\\temp.txt”, “r+”)

Answer : B

Question. Which of the following commands can be used to read “n” number of characters from a file using the file object <file>?
a) read(n)
b) n = file.read()
c) file.readline(n)
d) file.readlines()

Answer : A

Question. Which of the following commands can be used to read the remaining lines in a file using the file object <tmpfile>?
a) read(n)
b) read()
c) readline()
d) readlines()

Answer : C

Question. Each line of a text file is terminated by a special character, called?
a) End of file
b) End of byte
c) End of line
d) All the above

Answer : C

Question. Which function is used to read single line from file?
a) readline()
b) readlines()
c) readstatement()
d) readfullline()

Answer : A

Question. What is the expected output of the given code?
f = None
for i in range (5):
with open(“data.txt”, “w”) as f:
if i > 2:
break
print(f.closed)
a) True
b) False
c) None
d) Error

Answer : A

Question. Which method of pickle module is used to write onto a binary file?
a) dump()
b) load()
c) All of the above
d) None of the above

Answer : A

Question. Which of the following command is used to open a file “c:\temp.txt” in append-mode?
a) outfile = open(“c:\temp.txt”, “a”)
b) outfile = open(“c:\\temp.txt”, “rw”)
c) outfile = open(“c:\temp.txt”, “w+”)
d) outfile = open(“c:\\temp.txt”, “r+”)

Answer : A

Question. Which of the following commands can be used to read the next line in a file using the file object <tmpfile>?
a) read(n)
b) tmpfile.read()
c) readline()
d) tmpfile.readlines()

Answer : C

Question. Which of the following statements is not True
a) File method close() closes the opened file.
b) Python automatically closes a file when the reference object of a file is reassigned to another file.
c) close() method returns a value which ensures the termination of the file stream
d) Calling close( ) method more than once is allowed.

Answer : C

Question. The files that consists of human readable characters
a) Text file
b) Binary file
c) Both Text and Binary file
d) None of the above.

Answer : A

Question. Which function is used to close a file in python?
a) close()
b) stop()
c) end()
d) closefile()

Answer : A

Question. Which of the following file modes opens a file for appending and reading in a binary file and moves the files pointer at the end of the file if the file already exists or creates a new file?
a) a
b) a+
c) ab+
d) ab

Answer : C

Question. Which of the following commands can be used to read the entire contents of a file as a string using the file object <tmpfile>?
a) read(n)
b) read()
c) readline()
d) readlines()

Answer : B

Question. Which of the following statements is true with respect to the files in Python?
a) File can be opened with a file handle using open method without any arguments
b) File can be opened with a file handle using open method with one argument to read the file
c) File can be opened with a file handle using open method with one argument to write the file
d) File can be opened with a file handle using open method with one argument to append the file

Answer : B

Question. How many types of files are there in python?
a) 1
b) 2
c) 3
d) 4

Answer : B

Question. In file handling, what does this terms means “r, a”?
a) read, append
b) append, read
c) write, append
d) none of the mentioned

Answer : A

Question. Which of the following statements is/are true?
a) When you open a file for reading, if the file does not exist, an error occurs.
b) When you open a file for writing, if the file does not exist, a new file is created.
c) When you open a file for writing, if the file exists, the existing file is overwritten with the new file. (
d) All of the above.

Answer : D

Question. Which of the following command is used to open a file “c:\temp.txt” in write-mode only
a) outfile = open(“c:\temp.txt”, “w”)
b) outfile = open(file = “c:\temp.txt”, “w+”)
c) outfile = open(file = “c:\\temp.txt”, “w+”)
d) outfile = open(“c:\\temp.txt”, “w”)

Answer : D

Question. What does the <readlines()> method returns?
a) Str
b) a list of lines
c) list of single characters
d) list of integers

Answer : B

Question. To open a file only for reading which of the following statement cannot be used :
a) f = open(“PYTHON.txt”)
b) f = open(“PYTHON.txt”, “rt”)
c) f = open(“PYTHON.txt”, “r”)
d) f = open(“PYTHON.txt”,”r+”)

Answer : D

Question. Trying to open a binary file using a text editor will show:
a) Garbage values
b) ASCII values
c) Binary character
d) Unicodes

Answer : A

Question. A file maintains a __________ which tells the current position in the file where writing or reading will take place.
a) line
b) file pointer
c) list
d) order

Answer : B

Question. Rahul is assigned the task of storing the information of his class mates as student records in a text file “Stu2021.txt”.He wants to create a file to write the records. Which of the following is not a valid mode to open a file for writing the data?
a) w
b) r+
c) r 
d) w+

Answer : C

Question. Ajay is studying in an Engineering College in CSE branch. His sister, a class 12 student of Computer Science comes to him one day asking him the difference between r+ and w+ modes of a file. What is the correct answer Ajay would give to his sister?
a) No difference between r+ and w+
b) In r+ mode, the file is created if it does not exist and erases the content if the file already exists; w+ raises an error if the file does not exist
c) In w+ mode, the file is created if it does not exist and erases the content if the file already exists; r+ raises an error if the file does not exist 
d) Depends on the operating system

Answer : C

Case Study Questions on Text File

Question. Aishwarya is running her own boutique business. She wants to store data of all orders permanently and fast processing of data through her boutique software. Suggest her to choose the appropriate technique among the following.
a) She can use Python Dictionaries with Text files.
b) She can use Python Dictionaries with Binary file concept.
c) She can use Python Lists without the Binary files concept.
d) She can use Python Dictionaries without the Binary file concept.

Answer : B

Question. Given the directory structure in Q 23. Assume that the CWD is in the feline folder. What is the relative path to the file bears.gif?
a) C:/animals/ursine
b) animals/ursine
c) ..ursine/bears.gif
d) None of the above.

Answer : C

Question. In a program, there is a need of reading whole content of a textfile in a single shot and store it in the form of list. Suggest the best option among the following
a) read()
b) readline()
c) readlines()
d) None of the above

Answer : C

Question. A Student’s windows O/S got corrupted. He is trying to access his files through Command Prompt, but unable to find out all his Binary data files pertaining to his project. Help him to find out all his binary data files by suggesting the suitable extension name among the following.
a) .txt
b) .bin
c).dat
d) .com

Answer : C

Question. Given the directory structure in Q 23. Assume that the CWD is in the feline folder what is the relative path to lions.gif?
a) C:/animals/ursine
b) lions.gif
c) /animals/ursine/bears.gif
d) None of the above.

Answer : B

Question. A programmer has confusion in understanding the behaviour of opening a file in “w” mode. Clear his/her confusion, by suggesting the correct option among the given below. The behaviour of “w” mode is
a) Opening fails if the file already exists already.
b) Opening fails if the file does not exist already.
c) Opening will be succeeded if file exists with data and keeps the data intact.
d) Opening will be succeeded, if the file exists replaces the contents, do not exist, creates a new file.

Answer : D

Question. Given the directory structure in Q 23. Assume that the CWD is in the root folder where animals directory resides. What is the absolute path to bears.gif?
a) C:/animals/ursine
b) ../animals/feline
c) /animals/ursine/bears.gif
d) None of the above.

Answer : C

Question. Aditya is a class 12 student like you. He is practicing text file programming. He has a text file named names.txt. He wants to display all the names contained in the text file. He has written one of the following codes and succeeded in getting the output. Guess which among the following option might have given the correct output.
a) names = open(“names.txt”, “r”)
for line in names:
print(names)
c) names = open(“names.txt”, “r”)
for line in names:
print(“line”)
b) names = open(“names.txt”, “r”)
for line in names:
print(line)
d) names = open(“names.txt”, “r”)
for names in line:
print(line)

Answer : B

Question. Master Adithya could able to read contents of a text file part by part. Out of the following which option he would have been used?
a) read()
b) readlines()
c) readline()
d) readfullline()

Answer : C


Rohit of class 12 is asked by his Computer Science teacher to count the number of “the” and “and” in a text file “Book.txt”. He was able to do the task to some extent, but was confused in some areas. Help him out to complete the task
def displaytheand():
num=0 _________ #Statement 1
N=f.read()
M=N.split()
for x in M:
if x==”the” or x== “and”:
print(x) num=num+1 __________ #Statement 2
print(“Count of the/My in and:”,num) 

Question. Identify the correct statement that may be used in the place of statement 2
a) f.close()
b) f.close(“book.txt”)
c) close()
d) None of the above

Answer : A

Question. Which of the following is the correct one to be used in the place of statement 1
a) f=open(“Book.txt”,”w”)
b) f=open(“Book.txt”,”r”)
c) f=open(“Book.txt”,”a”)
d) F=open(“Book.txt”,”r”)

Answer : B


Rajitha, during Practical Examination of Computer Science, has been assigned an incomplete search() function to search in a text file “CAMP.txt”. The file “CAMP.txt” is created by his Teacher and the following information is known about the file
i) File contains details of camp describing events of an adventure camp in text format
ii) File contains details of adventure activities like caving, trekking, paragliding, rafting and rock climbing Rajitha has been assigned the task to complete the code and print the number of the word trekking
def search():
f = open(“CAMP.txt”,____) #Statement-1
A=____________________ #Statement-2
ct=0
for x in A:
p=x.split()
if p==”trekking”:
ct+=1
print(ct) _______________________# Statement-3 

Question. In which mode Rajitha should open the file in Statement-1?
a) r
b) r+
c) rb
d) wb

Answer : A

Question. Which statement should Rajitha use in Statement 3 to close the file.
a) file.close()
b) close(file)
c) f.close()
d) close()

Answer : C

Question. Name the function that can be used by Rajitha to read the content of the file in statement -2.
a) f.read( )
b) f.readline ()
c) f.readlines( )
d) f.readl()

Answer : C


Aparajitha joined an MNC company in Bangalore as a Python Programmer. Her task is to handle the data available for the company in the form of text files and perform the search operations based on specific criteria. Now she is asked to count the number of words in the file which start with “a” or “m” (both upper and lower cases) in a text file “Passion.txt”. She needs your help as she is stuck up with some statements. Please help her out to complete the task
def filecreate():
f=open(“Passion.txt”,”r”) #Statement 1
f.write() f.close() # Statement 2
def count_A_M():
f=open(“Passion.txt”,”r”) # Statement 3
A,M=0,0
r=f.read()
for x in r:
if x[0]==”A” or x[0]==”a” :
A=A+1 25 elif x[0]==”M” or x[0]==”m”: M=M+1
f.close()
print(“A or a: “,A)
print(“M or m: “,M) 

Question. Which of the following options can be used as statement 3
a) f=open(“Passion.txt”,”r”)
b) f=open(“Passion.txt”,”w”)
c) f=open(“Passion.txt”,”a”)
d) f=open(“Passion.txt”,”rt”)

Answer : A, B

Question. Choose the correct option to be used as statement 1
a) f=open(“Passion.txt”,”r”)
b) f=open(“Passion.txt”,”r+”)
c) f=open(“Passion.txt”,”w”)
d) f=open(“Passion.txt”,”a”)

Answer : C

Question. Choose the correct option to be used as statement 2
a) F.close()
b) f.close()
c) F.close(“passion.txt”)
d) No statement is required

Answer : B
 

Text file: opening a text file, text file open modes (r, r+, w, w+, a, a+), closing a text file, opening a file using with clause

Question. The mode “w+” is used to open the file for
a) Read and write a text file
b) Read and write a binary file
c) Write and Read a text file
d) Write and Read a binary file

Answer : C

Question. In r+ mode, if we write the file directly, it will
a) overwrite the beginning content
b) continue reading from the previous content
c) continue writing from the previous content
d) work like the append mode

Answer : A

Question. What is the default mode when the file is opened using the open() method ?
a) Write
b) Read
c) Write and read
d) Read and write

Answer : B

Question. Which of the following statements is true?
a) Python doesn’t write data to the file until you close the file using the close() method
b) If the file is opened for writing and is not closed, data is not written into the target file.
c) Python can write data to the file even if you do not close the file
d) None of the above

Answer : B

Question. (A) : If a file is opened using the “with” statement, you get better syntax and exceptions handling.
(B): When a file is opened using the “with” statement, it need not be closed using the close() function.
In the above two statements, which of the following is true?
a) Both A and B are Wrong
b) A is Wrong, but B is right.
c) A is right , but B is Wrong
d) Both A and B are right.

Answer : D

Question. The function read() is used to
a) Read the entire content of the file
b) Read the entire content of the file in the form of list
c) Read the content of the file line by line
d) Read each string of the content of the file

Answer : A

Question. When a file is opened in “w” mode, the file pointer is placed at
a) the beginning of the file.
b) The end of the file.
c) the middle of the file.
d) the current position of the file.

Answer : A

Question. When the file content has to be modified, we can use the ____________ mode
a) r
b) w
c) a
d) r+

Answer : A

Question. Which of the following statements is true with respect to closing a file
a) It is mandatory to close a text file which is opened
b) Python automatically closes a file
c) Python automatically closes a file if the reference object of the file is allocated to another
d) None of the above

Answer : C

Question. When a file is opened in “a” mode, the file pointer is placed at
a) the beginning of the file.
b) The end of the file.
c) the middle of the file.
d) the current position of the file.

Answer : B

MCQs for Text File Computer Science Class 12

Students can use these MCQs for Text File to quickly test their knowledge of the chapter. These multiple-choice questions have been designed as per the latest syllabus for Class 12 Computer Science released by CBSE. Our expert teachers suggest that you should practice daily and solving these objective questions of Text File to understand the important concepts and better marks in your school tests.

Text File NCERT Based Objective Questions

Our expert teachers have designed these Computer Science MCQs based on the official NCERT book for Class 12. We have identified all questions from the most important topics that are always asked in exams. After solving these, please compare your choices with our provided answers. For better understanding of Text File, you should also refer to our NCERT solutions for Class 12 Computer Science created by our team.

Online Practice and Revision for Text File Computer Science

To prepare for your exams you should also take the Class 12 Computer Science MCQ Test for this chapter on our website. This will help you improve your speed and accuracy and its also free for you. Regular revision of these Computer Science topics will make you an expert in all important chapters of your course.

Where can I access latest CBSE Class 12 Computer Science Text File MCQs?

You can get most exhaustive CBSE Class 12 Computer Science Text File MCQs for free on StudiesToday.com. These MCQs for Class 12 Computer Science are updated for the 2025-26 academic session as per CBSE examination standards.

Are Assertion-Reasoning and Case-Study MCQs included in the Computer Science Class 12 material?

Yes, our CBSE Class 12 Computer Science Text File MCQs include the latest type of questions, such as Assertion-Reasoning and Case-based MCQs. 50% of the CBSE paper is now competency-based.

How do practicing Computer Science MCQs help in scoring full marks in Class 12 exams?

By solving our CBSE Class 12 Computer Science Text File MCQs, Class 12 students can improve their accuracy and speed which is important as objective questions provide a chance to secure 100% marks in the Computer Science.

Do you provide answers and explanations for CBSE Class 12 Computer Science Text File MCQs?

Yes, Computer Science MCQs for Class 12 have answer key and brief explanations to help students understand logic behind the correct option as its important for 2026 competency-focused CBSE exams.

Can I practice these Computer Science Class 12 MCQs online?

Yes, you can also access online interactive tests for CBSE Class 12 Computer Science Text File MCQs on StudiesToday.com as they provide instant answers and score to help you track your progress in Computer Science.