TypeError:__init __()接受2个位置参数,但给出了6个位置

时间:2020-02-27 10:33:26

标签: python multiple-inheritance

class Person:
    def __init__(self,name):
        self.name=name
        print("person class is called")


class Teacher:
    def __init__(self,fname,lname):
        self.fname=fname
        self.lname=lname
        print("Techer class is called")


class Student(Person , Teacher):
    def __int__(self,sub,grade,name,fname,lname):
        self.sub=sub
        self.grade=grade
        Person.__init__(self,name)
        Teacher.__init__(self,fname,lname)
        print("student class is called")

    def getdata(self):
        print("subject name:",self.sub,"grade is:",self.grade)
        print("teacher name:",self.fname)


std1=Student("english","7.0","ravi","raj","savaliya")
std1.getdata()

1 个答案:

答案 0 :(得分:2)

您有一个错字__int__-> __init__。代替

class Student(Person , Teacher):
    def __int__(self,sub,grade,name,fname,lname):

应该有

class Student(Person , Teacher):
    def __init__(self,sub,grade,name,fname,lname):