ProgrammingHardInfosys HackWithInfy · TCS CodeVita

What does the following Python 3 code print? try: d = {} print(d["missing"]) except KeyError: print("KeyError")

  1. A. missing
  2. B. None
  3. C. NameError
  4. D. KeyError

Correct answer: D. KeyError

Indexing a dict with a key that isn't present raises KeyError, not a default value.

More Python Programming questions

Exams that ask this topic