Class 12 Computer Science Chapter 2 Important Questions with Answers PDF Download
FAQs on Important Questions and Answers for Class 12 Computer Science Chapter 2 File Handling in Python | 2026-27
1. Where can I download Class 12 Computer Science Chapter 2 Important Questions and Answers PDF?
Students can download the Class 12 Computer Science Chapter 2 Important Questions and Answers PDF from Vedantu to prepare for exams. It includes solved MCQs, short-answer questions, Python coding exercises and file-handling programs. Students can also explore chapter-wise PDF resources for Class 12 Computer Science important questions for additional revision.
2. What happens if an existing text file is opened in w+ mode?
Opening an existing file in w+ mode deletes its previous contents and allows both reading and writing. The file pointer initially starts at the beginning. After writing data, students can use seek(0) to return to the beginning before reading it.
3. Why does writelines() not display each string on a separate line?
The writelines() method writes the supplied strings exactly as provided. It does not automatically insert newline characters. To write each string on a separate line, students must include \n in the strings.
4. What happens when read() is called after the file pointer reaches the end of a file?
When the file pointer reaches the end of a text file, read() returns an empty string because no characters remain to be read. Students can use seek(0) to move back to the beginning and read the contents again.
5. Why should students use the with statement instead of open() and close() separately?
The with statement automatically closes the file when its block finishes, including when an exception occurs. This reduces the risk of leaving files open and makes file-handling programs easier to manage.
6. Can Python read and write data using the same file object?
Yes. Modes such as r+, w+ and a+ support both reading and writing. However, their behaviour differs. For example, r+ preserves existing contents when opened, while w+ clears them. Students should understand these differences before choosing a mode.
7. Why is EOFError used while reading binary files with pickle?
When a program repeatedly uses pickle.load() to retrieve stored objects, Python raises EOFError after the last object has been read. Students can catch this exception to stop the reading loop without an unexpected program termination.
8. Can a Python list or dictionary be stored directly in a text file?
The write() method for a text file accepts strings, not list or dictionary objects directly. Students can convert an object into a string before writing it. To preserve and retrieve Python objects in a binary file, they can use the pickle module.
9. How do I solve Class 12 Computer Science Chapter 2 Important Questions involving file modes?
First, identify whether the question requires reading, writing, appending or a combination of operations. Then choose the correct file mode and check whether the file must already exist. Finally, trace how each operation affects the contents and file pointer.
10. What happens if a file is opened in read mode but does not exist?
Python raises a FileNotFoundError when a program tries to open a non-existent file in read mode. Students can handle this exception with a try-except block or by checking whether the file exists before opening it.



















