Chapters
Python114 chapters

ReferenceDictionary methods

dict.get()

The value for a key, or a default instead of raising.

Signature

mapping.get(key, default=None)

Parameters

NameMeans
keywhat to look up
defaultreturned when the key is missing

Returns

The value, or the default.

Example

Python
person = {"name": "Ada"}
print(person.get("name"))
print(person.get("age"))
print(person.get("age", "unknown"))

Output

Ada
None
unknown

See also