Basics

None

None represents expected absence, distinct from missing keys and errors.

None is Python's value for “nothing here.” Check it with is None because it is a singleton identity value.

Source

result = None
print(result is None)

Output

True
abcNONETYPENone
`None` is a single object: every name that points at None points at the same object.

Functions often return None when absence is expected and callers can continue. The function name and surrounding code should make that possibility clear.

Source

def find_score(name):
    if name == "Ada":
        return 10
    return None

score = find_score("Grace")
print(score is None)

Output

True

A missing dictionary key is another absence boundary. Use get() when the mapping can supply a default, and use exceptions for invalid operations that cannot produce a value.

Source

profile = {"name": "Ada"}
print(profile.get("timezone", "UTC"))

try:
    int("python")
except ValueError:
    print("invalid number")

Output

UTC
invalid number

Notes

See also

Run the complete example

Example code

Expected output

True
True
UTC
invalid number

Execution time appears here after you run the example.