鱼C论坛

 找回密码
 立即注册
查看: 6501|回复: 3

python super()的小问题

[复制链接]
发表于 2016-5-24 10:51:25 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
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()为什么不对
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2016-12-5 13:22:18 | 显示全部楼层
求问楼主怎么解决的
我也遇到了这个问题
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2016-12-5 16:40:44 | 显示全部楼层
我也遇到过这样的,请问楼主是怎么解决的
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2016-12-5 17:02:41 | 显示全部楼层
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)
这样就行了
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 1 反对 1

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-5-16 17:18

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表