None
is just a value that commonly is used to signify ’empty’, or ‘no value here’.
If you write a function, and that function doesn’t use an explicit return statement, None
is returned instead, for example.
Another example is to use None
for default values. it is good programming practice to not use mutable objects as default values. Instead, use None
as the default value and inside the function, check if the parameter is None and create a new list/dictionary/whatever if it is.
Consider:
def foo(mydict=None):
if mydict is None:
mydict = {} # create a new dict for local namespace