Which exception is raised when accessing a dictionary key that does not exist?
- A IndexError
- B KeyError
- C ValueError
- D AttributeError
Answer
KeyError
Use dict.get() to return a default instead, or collections.defaultdict when a missing key should create a default value.





