← Quiz: Context Managers: all 10 questions
Quiz: Context Managers · Question 1 of 10
What is the main benefit of with open(...) as f:?
What is the main benefit of with open(...) as f:?
- A.The file is read faster
- B.The file is closed automatically, even if an error happens inside the block
- C.The file is opened in binary mode
- D.The file is copied to memory first
Answer & explanation
Correct answer: The file is closed automatically, even if an error happens inside the block
with calls the clean-up code whenever the block ends, normally or with an exception.
Can you get the rest right without peeking?
Take the timed Quiz: Context Managers quiz free. Pass it to earn XP and count towards your certificate.
Start the quiz →