类型错误:__init__() 需要 4 个位置参数,但给出了 7 个

Ayu*_*ani 0 python multiple-inheritance

class Employee(object):
    def __init__(self,ename,salary,dateOfJoining):
        self.ename=ename
        self.salary=salary
        self.dateOfJoining=dateOfJoining
    def output(self):
        print("Ename: ",self.ename,"\nSalary: ",self.salary,"\nDate Of 
Joining: ",self.dateOfJoining)
class Qualification(object):
    def __init__(self,university,degree,passingYear):
        self.university=university
        self.degree=degree
        self.passingYear=passingYear
    def qoutput(self):
        print("Passed out fom University:",self.university,"\nDegree:",self.degree,"\Passout year: ",self.passingYear)
class Scientist(Employee,Qualification):
    def __int__(self,ename,salary,dateOfJoining,university,degree,passingYear):
        Employee.__init__(self,ename,salary,dateOfJoining)
        Qualification.__init__(self,university,degree,passingYear)
    def soutput(self):
        Employee.output()
        Qualification.output()
a=Scientist('Ayush',20000,'21-04-2010','MIT','B.Tech','31-3-2008')
a.soutput()
Run Code Online (Sandbox Code Playgroud)

我无法找到问题的解决方案,也无法理解为什么会发生此 TpyeError。我是python的新手。谢谢

Roh*_*ohi 5

你的科学家类的 init 函数写为:

def __int__
Run Code Online (Sandbox Code Playgroud)

代替

def __init__
Run Code Online (Sandbox Code Playgroud)

所以发生的事情是它从它的父类继承了 init 函数,它接收的参数比你发送给这个类的要少。

此外,您应该使用 super 函数,而不是调用父母的 init。

super(PARENT_CLASS_NAME, self).__init__()
Run Code Online (Sandbox Code Playgroud)

这显然适用于所有父函数。