python super()的小问题
class Try_int(int):def __add__(self, other):
return super().__sub__(self, other)
>>> a = Try_int(3)
>>> b = Try_int(5)
>>> a + b
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
a + b
File "<pyshell#3>", line 3, in __add__
return super().__sub__(self, other)
TypeError: expected 1 arguments, got 2
这样用super()为什么不对 求问楼主怎么解决的
我也遇到了这个问题 我也遇到过这样的,请问楼主是怎么解决的 L丶 发表于 2016-12-5 16:40
我也遇到过这样的,请问楼主是怎么解决的
class Try_int(int):
def __add__(self, other):
return super().__sub__(other)
a = Try_int(3)
b = Try_int(5)
print(a + b)
这样就行了
页:
[1]