When a Python program is reading text from a file, after input is finished, another call to read returns an empty string to indicate that the end of the file has been reached.
A. End-of-file indicator
B. File reading error
C. Null character representation
D. Text parsing completion

Respuesta :

That's right! The empty string (`''`) returned by the `read` function is an **end-of-file indicator** (choice A).

In Python, when you use a function like `read()` on a file object, it tries to read a certain number of bytes (by default, all remaining bytes). If there's no more data to be read from the file (because you've reached the end), the function returns an empty string to signal this condition.

This is a common way to loop through the contents of a file in Python. Here's an example:

```python

with open("myfile.txt", "r") as f:

 line = f.readline()

 while line:

   # process the line

   print(line, end="")

   line = f.readline()

```

In this example, the `while` loop keeps iterating as long as `readline()` returns a non-empty string. When the end of the file is reached, `readline()` returns an empty string, and the loop terminates.

Q&A Education