None is a built-in constant that implies absence of value (or a null value):
- It can be used to assign "null" value to variables, function arguments or function returns;
- It's a singleton object (i.e. it always references to the same object);
- It's the sole instance of the
- It cannot be reassigned;
- It's considered falsy in a boolean context.
For example, you can assign
None to a variable in the following way:
foo = None print(foo) # None
Similarly, you can assign
None to a function/method argument (to serve as a default value), like so:
def foo(param = None): if param is None: return 'empty' print(foo()) # 'empty'
None can also be returned from a function:
def foo(): return None print(foo()) # None
When a function/method does not explicitly return a value, it is implicitly
def foo(): pass print(foo()) # None
Hope you found this post useful. It was published . Please show your love and support by sharing this post.