Skip to content

Glossary: Refactoring and Clean Code

dict.get

Also written: .get, `.get(key, default)`

A dict method that looks up a key and returns a default value if the key is missing. `DELIVERY.get(city, OTHER_CITIES)` avoids a KeyError for cities not in the table.

Where the book teaches it

Related terms

Lookup tableCommon Python errors (NameError, KeyError, ImportError, AttributeError)