File Handling in Python · Class 12 · CBSE · Science Computer Science
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.te…
Practice question from File Handling in Python (Class 12 · CBSE · Science Computer Science), with the correct answer and a step-by-step solution.
medium · MCQ · Q-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?
- A.CBSE 3
- B.CBS 3Correct answer
- C.CBS 6
- D.CB 2
Solution
read(3) reads the first three characters, CBS. The file pointer moves to position 3, so tell() returns 3.
More from File Handling in Python
- Which file mode opens a text file for writing by adding new data at the end without deleting its existing contents?
- Explain the purpose of the seek() and tell() functions when working with a file in Python.
- When the file pointer has reached the end of a text file, what does readline() return?
- What type of data is returned when a file is opened using open("data.bin", "rb") and its contents are read?
Practise more Computer Science
Sign up free for adaptive practice on this chapter, with instant feedback and hints on every question.
Start practising freeFree to start · No credit card needed