I recently came across this syntax, I am unaware of the difference.
I would appreciate it if someone could tell me the difference.
I recently came across this syntax, I am unaware of the difference.
I would appreciate it if someone could tell me the difference.
The answer is explained here.
To quote:
Practically-speaking, there is not much difference since custom comparison operators are rare. But you should use
is None
as a general rule.In this case, they are the same.
None
is a singleton object (there only ever exists oneNone
).is
checks to see if the object is the same object, while == just checks if they are equivalent.For example:
But since there is only one
None
, they will always be the same, andis
will return True.If you use numpy,
will give you error when numpy does elementwise comparison