为什么是第一个结果False,如果不是True?
>>> from collections import OrderedDict
>>> OrderedDict.__repr__ is OrderedDict.__repr__
False
>>> dict.__repr__ is dict.__repr__
True
Run Code Online (Sandbox Code Playgroud) 我有一个错误,我在使用时依赖于彼此相等的方法is.事实证明并非如此:
>>> class What(object):
def meth(self):
pass
>>> What.meth is What.meth
False
>>> inst = What()
>>> inst.meth is inst.meth
False
Run Code Online (Sandbox Code Playgroud)
为什么会这样?它适用于常规功能:
>>> def func():
pass
>>> func is func
True
Run Code Online (Sandbox Code Playgroud) 考虑以下代码:
class Person(object):
def sayHello(self):
return 'Hello'
print(Person().sayHello is Person().sayHello)
Run Code Online (Sandbox Code Playgroud)
我希望它能显示出真实.为什么显示False?
python ×3
identity ×2
methods ×2
class ×1
equality ×1
object ×1
python-2.7 ×1
python-3.x ×1
reference ×1