Computer Science (CS) III Mastery Practice Exam — Practice Test, Questions & Study Guide

Session length

1 / 20

Which function is used to read a file line by line in Python?

readlines()

The function that is specifically designed to read a file line by line in Python is the one that utilizes the readline method. This method reads a single line from the file each time it is called, making it useful for managing large files without loading the entire content into memory at once. When it is used in a loop, it allows the programmer to process the file one line at a time until the end of the file is reached. This functionality provides a more efficient and controlled reading process, which is especially beneficial when dealing with numerous lines of text.

The other listed options do not accurately describe methods used in standard Python file I/O operations. While readlines() can read all the lines at once into a list, it does not read them one by one interactively. The functions getlines() and fetchlines() are not part of Python's standard file handling methods; therefore, they are not applicable for reading files in this manner.

readline()

getlines()

fetchlines()

Next Question
Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy