CBSE Class 12 Computer Science Question 48 of 145

File Handling — Question 9

Back to all questions
9
Question

Question 9

Which of the following option is the correct Python statement to read and display the first 10 characters of a text file "Notes.txt" ?

  1. F = open('Notes.txt') ; print(F.load(10))
  2. F = open('Notes.txt') ; print(F.dump(10))
  3. F = open('Notes.txt') ; print(F.read(10))
  4. F= open('Notes.txt') ; print(F.write(10))
Answer

F = open('Notes.txt') ; print(F.read(10))

Reason — The syntax to read and display the first 10 characters of a text file is f = open(file-name) ; print(f.read(10)). Hence according to this syntax, F = open('Notes.txt') ; print(F.read(10)) format is correct.