The
is
operator does not match the values of the variables, but the instances themselves.
What does it really mean?
x is y
is same as id(x) == id(y)
, comparing identity of objects.
As @tomasz-kurgan pointed out in the comment below is
operator behaves unusually with certain objects.
E.g.
>>> class A(object):
... def foo(self):
... pass
...
>>> a = A()
>>> a.foo is a.foo
False
>>> id(a.foo) == id(a.foo)
True
Ref;
https://docs.python.org/2/reference/expressions.html#is-not
https://docs.python.org/2/reference/expressions.html#id24