本节index:算数运算符,反运算,一元操作,类型转换
>>> class New_int(int):
def __add__(self,other):
return int.__sub__(self,other)
def __sub__(self,other):
return int.__add__(self,other)
>>> a=New_int(3)
>>> b=New_int(5)
>>> a+b
-2
>>> a-b
8
>>>
>>> class Nint(int):
def __radd__(self,other):
return int.__sub__(self,other)
>>> a=Nint(5)
>>> b=Nint(3)
>>> a+b
8
>>> 1+b
2
>>>