Is " a is b " and " id(a) == id(b) " the same?

Chen 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):
...         pass
...     g=f

>>> b=a()
>>> print id(a.f), id(b.f), id(a.g), id(b.g)
6759528 6759528 6759528 6759528
>>> print a.f is b.f
False
>>> print a.f is a.g
False
>>> print b.f is b.g
False
>>> print a.g is b.f
False

Then, how to understand this example and the relationship of id() and 'is'?

I'm using 2.3a2 on win98, if it affects.

Chen







More information about the Python-list mailing list