🎙 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 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)
  1. A.missing: b
  2. B.missing: 'b'
  3. C.KeyError
  4. 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 →