← 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")
- A.A B
- B.A
- C.B
- 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 →