Which of the following options can be used to read the first line of a text file Myfile.txt?
a. myfile = open('Myfile.txt'); myfile.read()
b. myfile = open('Myfile.txt','r'); myfile.read(n)
c. myfile = open('Myfile.txt'); myfile.readline()
d. myfile = open('Myfile.txt'); myfile.readlines()
Answers & Comments
Answer:
To read the first line of a text file named 'Myfile.txt', you can use option C:
c. myfile = open('Myfile.txt'); myfile.readline()
This code will open the file, and `myfile.readline()` will read the first line of the file.
Verified answer
[tex]{\huge{\underline{\underline{\boxed{\blue{\mathscr{ Answer }}}}}}}[/tex]
The correct option to read the first line of a text file 'Myfile.txt' is:
c. myfile = open('Myfile.txt'); myfile.readline()
Option c will open the file and use the readline() method to read the first line of the file.