🎙 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 7 of 10

In a @contextmanager function, where should the clean-up code go?

In a @contextmanager function, where should the clean-up code go?

  1. A.Before the yield
  2. B.After the yield, inside a finally block
  3. C.In a separate exit method
  4. D.Inside an except block only
Answer & explanation

Correct answer: After the yield, inside a finally block

finally makes sure clean-up runs even when the with block raises.

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 →