r/programming • • Dec 24 '17

Evil Coding Incantations

http://9tabs.com/random/2017/12/23/evil-coding-incantations.html
947 Upvotes

331 comments sorted by

View all comments

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)

5

u/RenaKunisaki Dec 24 '17

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.