question about the id()
kyo guan
kyoguan at gmail.com
Sun May 15 22:48:21 EDT 2005
HI ALL:
Can someone explain why the id() return the same value, and why these values are changing? Thanks you.
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> class A(object):
... def f():
... pass
... def g():
... pass
...
>>>
>>> a=A()
>>> id(a.f)
11365872
>>> id(a.g)
11365872
>>>
>>>
>>> class B(object):
... def f():
... print 1
... def g():
... print 3
...
>>> b=B()
>>> id(b.f)
11365872
>>> id(b.g)
11365872
>>> id(a.f), id(a.g), id(b.f), id(b.g)
(11365872, 11365872, 11365872, 11365872)
>>> a.f is a.g
False
>>> id(a.f), id(a.g), id(b.f), id(b.g)
(11492408, 11492408, 11492408, 11492408)
>>> a.f is a.g
False
>>> id(a.f), id(a.g), id(b.f), id(b.g)
(11365872, 11365872, 11365872, 11365872)
>>>
More information about the Python-list
mailing list