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:
c. myfile = open('Myfile.txt'); myfile.readline()
Explanation:
The 'readline()' function can be used to read the first line of a text file Myfile. txt.
Verified answer
[tex]{\huge{\underline{\underline{\boxed{\pink{\mathscr{ Answer }}}}}}}[/tex]
To read the first line of a text file 'Myfile.txt', you can use the following option:
c. myfile = open('Myfile.txt'); myfile.readline()
Option c opens the file and uses the readline() method to read the first line of the file.