Turbo_J 2021-04-09 19:35 采纳率: 0%
浏览 101

python3继承super语法报错问题

class vehicle:
    def __init__(self,type):
        self.type=type
    def move(self):
        print('交通工具可以移动')

class airplane(vehicle):
    def __init__(self,type,color):
        super().__init__(type)  //super这种写法不会报错
        self.color=color
    def move(self):
        print('飞机飞')
class train(vehicle):
    def __init__(self,type,color):
        super(vehicle, self).__init__(type)  //super这种写法会报错
        self.color=color
    def move(self):
        print('火车在铁轨上移动')

a1=airplane(111,222)
a1.move()
t1=train('火车','白色')
t1.move()

    super(vehicle, self).__init__(type)
TypeError: object.__init__() takes exactly one argument (the instance to initialize)

  • 写回答

3条回答 默认 最新

  • 关注

    这条语句super(vehicle, self).__init__(type) //super这种写法会报错

    改为

    super().__init__(type,color) 

    评论

报告相同问题?

悬赏问题

  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集
  • ¥15 在启动roslaunch时出现如下问题
  • ¥15 汇编语言实现加减法计算器的功能
  • ¥20 关于多单片机模块化的一些问题
  • ¥30 seata使用出现报错,其他服务找不到seata
  • ¥35 引用csv数据文件(4列1800行),通过高斯-赛德尔法拟合曲线,在选取(每五十点取1点)数据,求该数据点的曲率中心。
  • ¥20 程序只发送0X01,串口助手显示不正确,配置看了没有问题115200-8-1-no,如何解决?
  • ¥15 Google speech command 数据集获取