Is " a is b " and " id(a) == id(b) " the same?
chenpuqing at 163.net
Sun Mar 16 07:05:17 CET 2003
Some one said that " a is b " is the same as " id(a) == id(b) ". But it
seems not always true from the following codes:
>>> class a:
... def f(self):
>>> print id(a.f), id(b.f), id(a.g), id(b.g)
6759528 6759528 6759528 6759528
>>> print a.f is b.f
>>> print a.f is a.g
>>> print b.f is b.g
>>> print a.g is b.f
Then, how to understand this example and the relationship of id() and 'is'?
I'm using 2.3a2 on win98, if it affects.
More information about the Python-list