# Enter a code 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 Student(Person): def __init__(self,name,gender,score): super(Student,self).__init__(name,gender) self.score = score class Tercher(Person): def __init__(self,name,gender,course): super(Tercher,self).__init__(name,gender) self.course = course class BasketballMixin(SkillMixin): def skill(self): return 'Skill is basketball' class FootballMixin(SkillMixin): def skill(self): return 'Skill is football' class BStudent(Student,BasketballMixin): def __init__(self,name,gender,score = 0): super(BStudent,self).__init__(name,gender,score) class FTercher(Tercher,FootballMixin): def __init__(self,name,gender,course = ' '): super(FTercher,self).__init__(name,gender,course) s = BStudent('Bob','Male') print('Studen\'s name is {}, Gender is {}, Skill is {}.'.format(s.name, s.gender ,s.skill())) t = FTercher('Alice','Female') print('Tercher\'s name is {}, Gender is {}, Skill is {}.'.format(t.name, t.gender ,t.skill()))
Line27和Line30,super()能不能不继承父类的全部参数?
可以用私有属性。
1、 super()._init_(param,param)这句话,调用了父类的初始化方法,那么如果需要传父类初始化方法的全部参数,但可以设置默认参数,就可以不传color这个参数,父类通过二个下划线设置私有属性。子类不能继承。