这怎么不升属性错误?函数对象没有任何比较方法。它是否以某种方式使用 id() ?
fun1 = lambda:x
fun2 = lambda:x
print fun1 == fun1 # True
print fun1 == fun2 # False
print fun1 > fun2 # True
print fun1 < fun2 # False
print fun1 > 1 # True
我知道它会比较地址,但是如何比较? 拦截 __lt__、__eq__ 等是否有一些低级黑客攻击?
最佳答案
Function objects不要定义自己的比较或丰富的比较。相反,它们继承自 type objects实现rich comparisons based on the object's address in memory .
所以是的,它有效地使用地址,就像内置的 id()功能。
在 Python 3 中,函数不再是可排序的。
关于python - python如何比较函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7942346/