CBSE Class 12 Computer Science Question 40 of 136

Data File Handling — Question 5

Back to all questions
5
Question

Question 5

To read two characters from a file object fobj, the command should be:

  1. fobj.read(2)
  2. fobj.read()
  3. fobj.readline()
  4. fobj.readlines()
Answer

fobj.read(2)

Reason — The command fobj.read(2) is used to read two characters from a file object fobj. The read() method without arguments (fobj.read()) reads the entire content of the file, while fobj.readline() reads a single line, and fobj.readlines() reads all lines and returns them as a list.