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.
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
- Dictionary
- Dictionary comprehension
- Docstring
- Dynamic typing
- enumerate
- Escape sequence
- Exception
- Exponentiation
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.