python 运算符重载的问题
>>> class Dog:
... def __cmp__(self,other):
... if other > 0 : return 1;
... elif other < 0 : return -1;
... else: return 0
...
>>> dog = Dog()
>>> if dog > -10 : print "ok"
...
>>> if dog < -10 : print "ok"
...
ok
>>> if dog == 0 : print "ok"
...
ok
>>>
这段代码一直不理解,为什么结果会是这样的,有懂的帮忙详细解释一下,谢谢了。 python??__cmp__
[解决办法]
if??dog??>??-10??其实就是
if??dog.__cmp__?(-10) 大于?0?
其余的两个我想应该你自己猜出来才行