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

  1. A.It makes reading faster
  2. B.It closes the file automatically, even if an error occurs
  3. C.It is required for "r" mode
  4. 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 →