>>> 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
最佳答案
它们在运行时绑定(bind);每次访问对象上的属性都会重新绑定(bind)该方法。当您将两者放在同一行时它们不同的原因是第一个方法在第二个方法绑定(bind)时尚未发布。
关于python - 为什么 python 引用中的绑定(bind)实例方法不相等?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5384621/