← Quiz: Exceptions and Files: all 15 questions
Quiz: Exceptions and Files · Question 12 of 15
What does this print? (code)
What does this print?
try:
d = {"a": 1}
print(d["b"])
except (KeyError, IndexError) as e:
print("missing:", e)
- A.missing: b
- B.missing: 'b'
- C.KeyError
- D.None
Answer & explanation
Correct answer: missing: 'b'
A tuple of exception types catches any of them. A KeyError shows the key with quotes.
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 →