>>> class foo(object):
... def test(s):
... pass
...
>>> a=foo()
>>> a.test is a.test
False
>>> print a.test
<bound method foo.test of <__main__.foo object at 0x1962b90>>
>>> print a.test
<bound method foo.test of <__main__.foo object at 0x1962b90>>
>>> hash(a.test)
28808
>>> hash(a.test)
28808
>>> id(a.test)
27940656
>>> id(a.test)
27940656
>>> b = a.test
>>> b is b
True
1 个解决方案
#1
7
They're bound at runtime; accessing the attribute on the object rebinds the method anew each time. The reason they're different when you put both on the same line is that the first method hasn't been released by the time the second is bound.
它们在运行时绑定;每次访问对象上的属性都会重新绑定方法。它们不同的原因是,当你把它们放在同一条线上时,第一个方法在第二次被绑定的时候还没有被释放。
#1
7
They're bound at runtime; accessing the attribute on the object rebinds the method anew each time. The reason they're different when you put both on the same line is that the first method hasn't been released by the time the second is bound.
它们在运行时绑定;每次访问对象上的属性都会重新绑定方法。它们不同的原因是,当你把它们放在同一条线上时,第一个方法在第二次被绑定的时候还没有被释放。