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 SheetPractice questions
- Question 1Q-1625A6See the answer and solution
Which file mode opens a text file for writing by adding new data at the end without deleting its existing contents?
- A.r
- B.a
- C.w
- D.r+
- Question 2Q-016F70See the answer and solution
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?
- A.CBSE 3
- B.CBS 3
- C.CBS 6
- D.CB 2
- Question 3Q-63D8E5See the answer and solution
Explain the purpose of the
seek()andtell()functions when working with a file in Python. - Question 4Q-C8C3F1See the answer and solution
When the file pointer has reached the end of a text file, what does
readline()return?- A.None
- B.An empty string
- C.-1
- D.An empty list
- Question 5Q-61CA91See the answer and solution
What type of data is returned when a file is opened using
open("data.bin", "rb")and its contents are read?- A.A string
- B.A bytes object
- C.A list of characters
- D.A dictionary
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 freeFree to start · No credit card needed