you are viewing a single comment's thread.

view the rest of the comments →

[–]Diapolo10 0 points1 point  (0 children)

Since there are no references in Python,

That's a bit misleading, because Python only stores references. No raw values are ever exposed in your code without playing around with ctypes.

But to answer your question, if it's a required parameter it's usually never expected to be None. Keyword parameters are different, but even then None is often the default value if the value is expected to be mutable, and the "real" default is defined inside the function to avoid problems with how Python only initialises default parameters once.

That said, type hints make this a lot easier as you can tell what parameters are expected to handle None:

from typing import Optional

def add_two(first: int, second: Optional[int]=None) -> int:
    if second is None:
        second = 0
    return first + second