QuestionQ5

VerifiedMiscellaneous (List Comprehensions, Lambdas, Closures, I/O)

What output is expected from the following code when the file named zero_length_existing_file is a zero-length file in the working directory?

Question Image

Explanation

For a text stream already at end-of-file, readline() returns an empty string. The length of that string is 0, so print(len(d)) prints 0; opening the existing file does not raise IOError.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!