'is None' VS '== None' in Python
They actually have a discussion about it
- https://stackoverflow.com/questions/14247373/python-none-comparison-should-i-use-is-or
- https://softwareengineering.stackexchange.com/questions/321861/var-is-none-vs-var-none/322394
Why use X is None
For this one, there’s only has one condition where X is None, which is X = None
.
Why use X == None
For this one, there’s has multiple conditions where X == None, for example:
X = [1,2,3]
X == X[:] # This is True since two of them are "equivalent"
X is X[:] # This is False since they're actually different objects
For me, I think X[:] and X are exactly the same things. If you doubt, check the javascript syntax.
In my opinion
It’s silly to have a keyword called is
in there because other programming languages don’t have it.
It increases the difficulty to master a lot of programming languages at the same time.
And it is unnecessary according to the difference showed in here.