小编Sor*_*rif的帖子

Python 2.7 __init __()只需要2个参数(给定3个)

我有这些课程. Person是父类,Student是子类:

class Person(object):
    def __init__(self, name):
        self.name = name

class Student(Person):
    def __init__(self, avr, name):
        self.avr = avr
        super(Student, self).__init__(self, name)
Run Code Online (Sandbox Code Playgroud)

当我尝试创建一个实例时,我收到此错误Student:

__init__() takes exactly 2 arguments (3 given)
Run Code Online (Sandbox Code Playgroud)

我的代码出了什么问题?

python inheritance super

1
推荐指数
1
解决办法
2303
查看次数

标签 统计

inheritance ×1

python ×1

super ×1