Chapter 4 · Class 12 · CBSE · Science Computer Science

File Handling in Python

25 practice questions · 5 marks weightage

Topics in this chapter

  • Text File Reading
  • File Modes and Context Managers
  • Text File Writing
  • File Pointers and Positioning
  • Line Processing and CSV
  • Binary Files and Pickle

Cheat sheet

Cheat Sheet

Practice questions

  1. Question 1Q-1625A6

    Which file mode opens a text file for writing by adding new data at the end without deleting its existing contents?

    1. A.r
    2. B.a
    3. C.w
    4. D.r+
    See the answer and solution
  2. Question 2Q-016F70

    Consider the following Python code: with open("marks.txt", "w") as f: f.write("CBSE12") with open("marks.txt", "r") as f: print(f.read(3)) print(f.tell()) What will be displayed?

    1. A.CBSE 3
    2. B.CBS 3
    3. C.CBS 6
    4. D.CB 2
    See the answer and solution
  3. Question 3Q-63D8E5

    Explain the purpose of the seek() and tell() functions when working with a file in Python.

    See the answer and solution
  4. Question 4Q-C8C3F1

    When the file pointer has reached the end of a text file, what does readline() return?

    1. A.None
    2. B.An empty string
    3. C.-1
    4. D.An empty list
    See the answer and solution
  5. Question 5Q-61CA91

    What type of data is returned when a file is opened using open("data.bin", "rb") and its contents are read?

    1. A.A string
    2. B.A bytes object
    3. C.A list of characters
    4. D.A dictionary
    See the answer and solution

20 more questions on File Handling in Python

Sign up free to practise the full chapter. Questions you get wrong come back until you've mastered them.

Start practising free

Free to start · No credit card needed