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?

  1. A.CBSE 3
  2. B.CBS 3Correct answer
  3. C.CBS 6
  4. 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

All of File Handling in Python

Practise more Computer Science

Sign up free for adaptive practice on this chapter, with instant feedback and hints on every question.

Start practising free

Free to start · No credit card needed