Does Python Have a "null" Value?

Find out if Python has a null value or not

Python does not have a "null" value. However, you can use the "None" keyword instead to represent null values, which implies absence of value. None can be used with variables, function/method arguments or return value, etc.

For example, assigning None to a variable implies it has no value (or "null" value):

foo = None

print(foo) # None

To check whether a variable is None or not, you can use the is (or is not) operator.

Similarly, you could assign None to function arguments (to serve as a default value when an argument is not passed to the function) or as a return value from a function:

def foo(param = None):
    if param is None:
        return 'empty'

print(foo()) # 'empty'
def foo():
    return None

print(foo()) # None

Hope you found this post useful. It was published . Please show your love and support by sharing this post.