小编Ale*_*per的帖子

为什么python引用中的绑定实例方法不相等?

>>> 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
Run Code Online (Sandbox Code Playgroud)

python equality sentinel

9
推荐指数
1
解决办法
250
查看次数

标签 统计

equality ×1

python ×1

sentinel ×1