QuestionQ29

Miscellaneous (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

  • A An errno value corresponding to file not found
  • B 2
  • C 1
  • D 0
Explanation

Opening an existing zero-length file succeeds. readline() returns an empty string at end-of-file, and len('') is 0, so the program prints 0.

Community Discussion

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