AI engineering glossary · Python core

What is dict.get?

dict.get: A dictionary method that looks up a key and returns its value, or a default value (None unless given) if the key is missing. It avoids the KeyError that plain square-bracket lookup raises.

Level: intermediateTopic: Python core

dict.get: an example

prices = {'tea': 15}; prices.get('tea') is 15, prices.get('cake', 0) is 0, while prices['cake'] raises KeyError.

Related terms

More Python core terms

Where you learn it

dict.get 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.