Computer Science, asked by kushwahaabhijeet607, 3 months ago

22. Which of the following commands can be used to read the
entire contents of a file as a string using the file object <file>?
a. file.read(n)
b. file.readline
Ps. Offiche
c. file.reado
d. file.readlines()
non ho mrad to read the

Answers

Answered by jaedensujan2011
6

Answer:

i think (a) is the answer not sure..

Answered by kartavyaguptasl
1

Answer:

The correct option for the command to read the entire contents of a file as string using the object <file> is found to be option (d) file.readlines() .

Explanation:

In Python, we can read the contents of the file opened in read or read and write mode by the following commands:

file.read([n]) - This command reads the whole content of the file if and only if 'n' is not specified while calling the function. Otherwise if 'n' is given, this command will read the content of the file up to 'n' bytes/index.

file.readline([n]) - This command reads a single line and will not be useful for reading more than one line and if 'n' is specified, reads up to 'n' bytes/index of the line.

file.readlines() - This command is used for reading the whole content of the file specified (reads all the lines of the file) and returns the output as each line as a single string element of a list/array.

#SPJ3

Similar questions