Here’s a 15-question “Text File Quiz Class 12” based on the topic “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, writing/appending data to a text file using write() and writelines(), reading from a text file using read(), readline() and readlines(), seek and tell methods, manipulation of data in a text file

Text File Quiz Class 12

1. How do you open a text file in read mode in Python?

 
 
 
 

2. Which open mode allows both reading and writing in a text file without truncating the file?

 
 
 
 

3. What is the purpose of the “a” mode when opening a text file?

 
 
 
 

4. How can you close an open text file in Python?

 
 
 
 

5. What is the benefit of using the with statement when opening a file?

 
 
 
 

6. Which method is used to write a single string to a text file in Python?

 
 
 
 

7. How can you move the cursor position in a text file to a specific byte using Python?

 
 
 
 

8. What does the tell() method return in a text file?

 
 
 
 

9. In the context of text files, what does the readline() method do?

 
 
 
 

10. How can you append multiple lines to a text file at once in Python?

 
 
 
 

11. Which method is used to read the entire content of a text file into a string in Python?

 
 
 
 

12. What is the purpose of the “w+” mode when opening a text file?

 
 
 
 

13. How can you check if a file exists before attempting to open it in Python?

 
 
 
 

14. What is the purpose of the seek(0) method in a text file?

 
 
 
 

15. How can you read all lines from a text file into a list in Python?

 
 
 
 

Copywrite © 2020-2024, CBSE Python,
All Rights Reserved