by aktuel · 6y ago · 0 comments
>>> x = 25 * 37
>>> y = 25 * 37
>>> x is y
False
>>> x == y
True
From my understanding, '==' checks for equality and 'is' checks that the variables reference the same address.
>>> a=16
>>> a*a is a*a
True
>>> a=17
>>> a*a is a*a
False
WTFSee https://stackoverflow.com/questions/306313/is-operator-behav... for some discussion and further related links.
At the CPython level, you can explain it in terms of the particular range of small integers that are interned and thus are guaranteed within particular CPython versions to share object identity when they have value equality.
But just knowing that is identity and == is equality is mostly enough to use them correctly.