Python's None: Null in Python
Bart Willems on July 28, 2020
I still struggle with “because None is a singleton you have to use is, and what I found it this:
In most cases == and is return the same result, but it’s possible to have objects where the equality operator is overriden and might give a wrong result (simplified example):
def __eq__(self, other):
x = Foo()
x == None # True
x is None # False
Because the equality operator can give you the wrong answer you should use is, but because None is a singleton it might lead you to think you can use == as well. Which will work in many cases—and then you’ll spend hours figuring out why your code doesn’t work.
Become a Member to join the conversation.