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

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) 

    评论

报告相同问题?