问答详情
源自:3-4 Python中的多态

继承的两个父类的参数不一致,子类应该怎么写

class Person(object):

    def __init__(self, name, gender):

        self.name = name

        self.gender = gender

class Skillmixin(object):

    def __init__(self,skill):

        self.skill=skill

class Teacher(Person):

    def __init__(self, name, gender, course):

        super(Teacher, self).__init__(name, gender)

        self.course = course

class FootballMixin(Skillmixin):

    def __init__(self,skill,sex):

        super(FootballMixin,self).__init__(skill)

        self.sex=sex

class Football_teacter(Teacher,FootballMixin):

    def __init__(self,name,gender,course,skill,sex,color):

        super(Football_teacter,self).__init__(name, gender, course)

#        super(Teacher,self).__init__(skill,sex)


        self.color=color

s = Football_teacter('Bob', 'golor', '数学','ccc','足球','hot')

print(s.color)

print(s.name)

print(s.gender)

print(s.course)

print(s.skill)

print(s.sex)


提问者:浮___雲 2021-05-18 11:30

个回答

  • 慕九州4260586
    2021-05-19 20:23:32

    class P(object):

        def __init__(self,name):

            self.name = name


    class Skill(object):

        def __init__(self,skill):

            self.skill = skill

      

    class F(Skill):

        def __init__(self,skill):

            super(F,self).__init__(skill)

            #self.skill = 'football'


    class B(Skill):

        def __init__(self,skill):

            super(B,self).__init__(skill)

            #self.skill = 'basketball'

            

    class S(P, B):

        def __init__(self,name,skill):

            P.__init__(self,name)

            B.__init__(self,skill)

            print ('{}打{}'.format(self.name,self.skill))

        

    class T(P, F):

        def __init__(self,name,skill):

            P.__init__(self,name)

            F.__init__(self,skill)

            print ('{}打{}'.format(self.name,self.skill))


            

    S('student','basketball')

    T('teacher','football')