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

来源:3-4 Python中的多态

浮___雲

2021-05-18 11:30

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)


写回答 关注

1回答

  • 慕九州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')


Python3 进阶教程(新版)

学习函数式、模块和面向对象编程,掌握Python高级程序设计

41910 学习 · 236 问题

查看课程

相似问题