← Quiz: Exceptions and Files: all 15 questions
Quiz: Exceptions and Files · Question 5 of 15
Why use with open(...) as f:?
Why use with open(...) as f:?
- A.It makes reading faster
- B.It closes the file automatically, even if an error occurs
- C.It is required for "r" mode
- D.It encrypts the file
Answer & explanation
Correct answer: It closes the file automatically, even if an error occurs
The with statement guarantees the file is closed when the block ends.
Can you get the rest right without peeking?
Take the timed Quiz: Exceptions and Files quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →