Use dict.get when retrieving a dictionary value should remain safe if the key is absent. Pass the key and, optionally, a fallback value; Python returns None when the fallback is omitted instead of raising KeyError. section 3.4.4
urgencies.get("Homework")
# output: 5
urgencies.get("Homeworks", "N/A")
# output: 'N/A'
urgencies.get("Homeworks")
# output: None (None is automatically hidden in an interactive console)
These calls show retrieval of an existing value, an explicit fallback, and the implicit None fallback. section 3.4.4
Choose the access pattern according to the behavior you want:
- Use get(key, default) when a missing key has a meaningful fallback, such as "N/A", 0, or "normal". section 3.4.4
- Use get with **kwargs when a function accepts optional keyword arguments and each option needs a default. section 3.4.4
- Prefer dict[key] when a missing or misspelled key should raise KeyError and reveal a problem during development. section 3.4.6 section 3.7
- Do not substitute setdefault casually: it also inserts the fallback into the dictionary when the key is missing. section 3.4.5
Defaults for optional keyword arguments
A function can read optional settings without checking each key first: kwargs.get("kwarg0", 0), kwargs.get("kwarg1", "normal"), and kwargs.get("kwarg2", []). Calls may omit every option or provide only selected ones. section 3.4.4
The practical distinction is error policy: get handles uncertain input gracefully, while subscripting deliberately surfaces unexpected keys. Use the explicit fallback only when that behavior is appropriate. section 3.4.6 section 7.2.5




