AI engineering glossary · Python core
What is keyError?
KeyError: A built-in exception raised when a dictionary lookup uses a key that is not present. Use in or dict.get to avoid it. The missing key is shown in the error message, which helps locate the mistaken lookup or a typo in the key.
KeyError: an example
d = {'a': 1}; d['b'] raises KeyError: 'b', while d.get('b') returns None.
Related terms
More Python core terms
Where you learn it
KeyError is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.