QuestionQ60

VerifiedExceptions

What is the expected output of the following code when existing_file is the name of a file located in the working directory?

Question Image

Explanation

Opening a writable file in 'w' mode does not raise IOError; the mode creates the file when needed or truncates an existing file. Therefore, 1 is printed in the try block and 3 is printed in the else block, producing 1 3.

Community Discussion

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