Is "None" the Same as "null" in Python?

Python None vs Null

Unlike some other programming languages (such as Java, C/C++, JavaScript, PHP, etc.), Python does not have a "null" value. Instead, Python has a built-in "None" constant that is semantically the same — i.e. they're both used to represent absence of value, or no value. Therefore, you can use None to represent null values in Python.

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(arg = None):
    if arg 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 None:

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.