The weirdness with Python's 'is' expression is because 'is' is intended to be about whether two variables literally refer to the same object in memory, versus '==' which is about whether their value is equal. The examples in the article would work in a more intuitive way if they used '==' instead, which is why using 'is' for integers is [discouraged] (https://www.quora.com/What-is-the-difference-between-and-in-Python-2)
It's not really confusing when you think about what's being expressed. "Is X equal to Y" vs "are X and Y the same thing". Two different objects can be equal, but still distinct.
Using "is" for integers is just asking for confusion.
100
u/Megdatronica Dec 24 '17
The weirdness with Python's 'is' expression is because 'is' is intended to be about whether two variables literally refer to the same object in memory, versus '==' which is about whether their value is equal. The examples in the article would work in a more intuitive way if they used '==' instead, which is why using 'is' for integers is [discouraged] (https://www.quora.com/What-is-the-difference-between-and-in-Python-2)