Python 2.7 __init__() takes exactly 2 arguments (3 given)

前端 未结 2 1159
长情又很酷
长情又很酷 2021-01-25 07:31

I\'ve got these classes. Person is the parent class and Student is the child class:

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


        
2条回答
  •  北海茫月
    2021-01-25 08:24

    If you are using super, you don't pass self to the target method. It is passed implicitly.

    super(Student, self).__init__(name)
    

    That's 2 arguments total (self, name). When you passed self, that was 3 total (self, self, name).

提交回复
热议问题