Computer Science
Which of the following option is the correct Python statement to read and display the first 10 characters of a text file "Notes.txt" ?
- F = open('Notes.txt') ; print(F.load(10))
- F = open('Notes.txt') ; print(F.dump(10))
- F = open('Notes.txt') ; print(F.read(10))
- F= open('Notes.txt') ; print(F.write(10))
Python File Handling
2 Likes
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.
Answered By
1 Like
Related Questions
Which of the following mode will refer to binary data ?
- r
- w
- +
- b
Which of the following statement is not correct ?
- We can write content into a text file opened using 'w' mode.
- We can write content into a text file opened using 'w+' mode.
- We can write content into a text file opened using 'r' mode.
- We can write content into a text file opened using 'r+' mode.
Which of the following is not a correct Python statement to open a text file "Notes.txt" to write content into it ?
- F = open('Notes.txt', 'w')
- F = open('Notes.txt., 'a')
- F = open('Notes.txt', 'A')
- F = open('Notes.txt', 'w+')
Which function is used to read all the characters ?
- read()
- readcharacters()
- readall()
- readchar()