In Python, None is in fact a falsy value (i.e. it evaluates to False in a boolean context).
For example, when you explicitly cast None to a boolean, it would return False:
print(bool(None)) # False
Similarly, when you use None in a boolean context, it's evaluated to False:
if None:
# do something
# equivalent to
if bool(None):
# do something
if not None:
# do something
# equivalent to
if not bool(None):
# do something
This post was published by Daniyal Hamid. Daniyal currently works as the Head of Engineering in Germany and has 20+ years of experience in software engineering, design and marketing. Please show your love and support by sharing this post.