🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← 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:?

  1. A.The file is read faster
  2. B.The file is closed automatically, even if an error happens inside the block
  3. C.The file is opened in binary mode
  4. 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 →