super(Human,self)的写法总是报错

来源:9-15 子类方法调用父类方法:super关键字

2339633

2021-02-23

用python3.8.6 执行的时候总是报错

super(Human,self).init(name,age)

TypeError: object.init() takes exactly one argument (the instance to initialize)

写回答

2回答

o杨飞o

2022-05-31

class Student(People):
    # 定义变量
    __school = 0

    def __init__(self, school, name, age):
        self.__school = school
        # 实现父类
        super().__init__(name, age)

    def info(self):
        # 调用父类的方法
        super().show()
        print('school:', self.__school)

我是这样写的。

0
0

ImClever

2021-05-08

super(Student, self)

0
0

Python3.8系统入门+进阶 (程序员必备第二语言)

语法精讲/配套练习+思考题/原生爬虫实战

14598 学习 · 4469 问题

查看课程