Ale*_*per 9 python equality sentinel
>>> 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)
他们在运行时受到约束; 访问对象上的属性每次重新绑定该方法.当你把它们放在同一条线上时它们不同的原因是第一种方法在第二种方法绑定时尚未释放.
| 归档时间: |
|
| 查看次数: |
250 次 |
| 最近记录: |