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.

Level: beginnerTopic: Python core

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.

Before you go

Take the cheat sheet with you

One free PDF: the key AI-engineering terms, formulas and Python idioms. No spam; unsubscribe any time.