get()
Safely gets a key's value.
Syntax
dict.get(key, default)
Description
If the key exists it returns its value; otherwise it returns the default you give (or None). Unlike square brackets, it doesn't raise an error.
Returns
The value or the default.
Example
Loading editor…
Expected output
Alex 0
When to use?
Reading fields that might be missing without crashing (settings, API data).