|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
class nstr(str):
def __init__(self,arg=''):
self.total=0
for each in arg:
self.total+=ord(each)
def __add__(self,other):
return self.total+other.total
def __sub__(self,other):
return self.total-other,total
def __mul__(self,other):
return self.total*other.total
def __truediv__(self,other):
return self.total/other.total
>>> a+B
899
>>> a-B
Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
a-B
File "C:/Users/lenovo/AppData/Local/Programs/Python/Python36-32/自定义加减乘除.py", line 10, in __sub__
return self.total-other,total
TypeError: unsupported operand type(s) for -: 'int' and 'nstr'
>>>
def __sub__(self,other):
return self.total-other,total
你不小心把点打成了逗号。
|
|