In [10]: class hi:
....: def __lt__(self,other):
....: print other
....:
....:
In [11]: x = hi()
In [12]: x < "s"
s
魔术方法、调用方式、解释:
- __new__(cls [,...])
instance = MyClass(arg1, arg2)
__new__ 在创建实例的时候被调用
- __init__(self [,...])
instance = MyClass(arg1, arg2)
__init__ 在创建实例的时候被调用
- __cmp__(self, other)
self == other, self > other, 等。
在比较的时候调用
- __pos__(self)