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

What does this print? (code)

What does this print?

from contextlib import suppress
with suppress(ZeroDivisionError):
    x = 1 / 0
    print("A")
print("B")
  1. A.A B
  2. B.A
  3. C.B
  4. D.An error
Answer & explanation

Correct answer: B

The division raises, the rest of the block is skipped, suppress swallows the error, and B is printed.

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 →