a
askaideAI
Log in
— CHAPTER MASTERY · CLASS 12

File Handling in Python Important Questions.

Master File Handling in Python with AI-powered practice. Our adaptive tutor identifies your gaps and provides step-by-step explanations for every topic in this chapter.

File Handling in Python — Important Questions with Answers

Practice these File Handling in Python questions for Class 12 Computer Science, each with the correct answer and a step-by-step explanation. Sign up free to practice all 65+ questions with adaptive difficulty.

  1. Q1Easy

    What is the primary purpose of the `pickle` module in Python?

    • A.Reading text files
    • B.Writing text files
    • C.Serialization and deserialization of Python objects
    • D.Managing file pointers
    Answer: Serialization and deserialization of Python objects

    Explanation: The `pickle` module is used to serialize and deserialize Python objects, allowing complex data types to be saved to a binary file and later restored. This process is essential for data persistence in Python applications.

  2. Q2Easy

    Which mode is used to open a file for both reading and writing in Python?

    • A.w
    • B.a
    • C.r+
    • D.rb
    Answer: r+

    Explanation: The 'r+' mode allows a file to be opened for both reading and writing. This means you can read existing content and also write new content to the file without truncating it.

  3. Q3Easy

    What happens when you open a file in write mode ('w')?

    • A.File is opened for reading
    • B.File is opened for appending
    • C.All contents will be overwritten if the file exists
    • D.File cannot be created
    Answer: All contents will be overwritten if the file exists

    Explanation: When a file is opened in write mode ('w'), if the file already exists, all its contents will be erased. If it does not exist, a new file will be created. This is important to remember to avoid accidental data loss.

  4. Q4Easy

    What is the main difference between text files and binary files?

    • A.Both are human-readable
    • B.Text files are larger than binary files
    • C.Text files are human-readable, binary files are not
    • D.Binary files can only store images
    Answer: Text files are human-readable, binary files are not

    Explanation: Text files contain human-readable characters and can be opened with any text editor, while binary files consist of non-human readable data that requires specific software to interpret. This fundamental difference affects how data is stored and accessed.

  5. Q5Medium

    What method is used to read a specified number of bytes from a file in Python?

    • A.read()
    • B.readlines()
    • C.writelines()
    • D.write()
    Answer: read()

    Explanation: The read() method is specifically designed to read a certain number of bytes from a file. It allows you to specify how many bytes you want to read, making it useful for reading large files in chunks.

  6. Q6Medium

    Which file mode is used to open a file for both reading and writing in Python?

    • A.r
    • B.w
    • C.a
    • D.r+
    Answer: r+

    Explanation: The 'r+' mode allows you to read and write to a file simultaneously. This mode is useful when you need to modify existing content without truncating the file.

  7. Q7Medium

    What does the pickle module in Python do?

    • A.Compresses files
    • B.Encrypts data
    • C.Serializes and de-serializes Python objects
    • D.Converts text to binary
    Answer: Serializes and de-serializes Python objects

    Explanation: The pickle module is used for serializing Python objects, which means converting them into a byte stream that can be saved to a file or transmitted over a network. It allows for easy storage and retrieval of complex data structures.

  8. Q8Medium

    What happens when you open a file in append mode ('a+')?

    • A.You can only read
    • B.You can only write
    • C.You can read and write at the end
    • D.You cannot read or write
    Answer: You can read and write at the end

    Explanation: Opening a file in append mode allows you to add new data at the end of the file while still being able to read existing data. This is useful for logging or adding entries without losing previous content.

  9. Q9Hard

    What does the tell() method return in Python file handling?

    • A.Current position of the file object
    • B.Total size of the file
    • C.Last modified time of the file
    • D.File access mode
    Answer: Current position of the file object

    Explanation: The tell() method is used to determine the current position of the file object in the file. It returns an integer that indicates the byte position from the beginning of the file to the current position of the file object.

  10. Q10Hard

    Which file mode allows both reading and writing in Python?

    • A.r
    • B.w
    • C.a
    • D.r+
    Answer: r+

    Explanation: The 'r+' mode in Python allows a file to be opened for both reading and writing. This means you can read from and write to the same file without needing to close and reopen it.

  11. Q11Hard

    What is the purpose of the close() method in file handling?

    • A.To read data from the file
    • B.To write data to the file
    • C.To free up system resources
    • D.To append data to the file
    Answer: To free up system resources

    Explanation: The close() method is essential in file handling as it releases all the resources associated with the file, such as memory and processor time. Failing to close a file can lead to memory leaks and other resource management issues.

  12. Q12Hard

    What does the 'wb+' mode do when opening a file?

    • A.Opens the file in read mode
    • B.Opens the file in write mode
    • C.Opens the file in read, write, and binary mode
    • D.Opens the file in append mode
    Answer: Opens the file in read, write, and binary mode

    Explanation: The 'wb+' mode opens a file for both reading and writing in binary format. If the file already exists, its contents will be overwritten; if it does not exist, a new file will be created.

Practice all 65+ File Handling in Python questions — free

Start Free Practice

How AskAide helps with File Handling in Python

Exam-Ready Questions

Practice questions specifically designed for CBSE Class 12 Computer Science board exams. Covers all difficulty levels from basic to advanced.

Instant AI Doubts

Stuck on a tricky concept in File Handling in Python? Our AI tutor provides immediate, step-by-step explanations 24/7.

Adaptive Practice

The difficulty adjusts as you learn. Master foundations first, then move to challenging board-level problems.

Why practice File Handling in Python on AskAide?

Preparing for board exams requires more than just reading File Handling in Python from the textbook. You need to apply concepts to different types of problems. AskAide's AI-powered platform makes this process seamless for Class 12 students.

Our question bank for File Handling in Python is generated from the NCERT chapter text itself, so every question stays inside the syllabus. Whether it's complex numericals or conceptual theory, our AI tutor helps you break down every problem.

  • Unlimited practice questions for File Handling in Python
  • Personalized feedback on your weak areas
  • NCERT-aligned curriculum for Computer Science
  • Free access for students across India

Ready to ace your exams?

Students across India are already practising their chapters on AskAide — free during early access.

Try for free now
Menu