Tuesday, 27 August 2013

Why the python class method is different with it's object method but both of them have the same id?

Why the python class method is different with it's object method but both
of them have the same id?

While I'm studying the python attributes and methods, and read to the
Example 1.2. A function is more. I try to do a simple test base on the
example, but the result makes me a little confused.
>>> class foo(object):
... def fun(self):
... pass
...
>>> f = foo()
>>> f.fun is foo.fun
False
>>> id(f.fun)
36093064
>>> id(foo.fun)
36093064
>>>
python version, 2.7.5 operation sys, win8
Why the 'is' test return False but the id return the same value? I
expected to see the difference ids in the beginning. Thanks in advance!

No comments:

Post a Comment