# Enter a code class Person(object): def __init__(self, name, gender): self.name = name self.gender = gender def who(self): return 'I am a Person, my name is %s' % self.name class Student(Person): def __init__(self, name, gender, score): super(Student, self).__init__(name, gender) self.score = score def who(self): return 'I am a Student, my score is %s' % self.score class Teacher(Person): def __init__(self, name, gender, course): super(Teacher, self).__init__(name, gender) self.course = course def who(self): return 'I am a Teacher,teching %s'%self.course class SkillMixin(object): def __init__(self): pass def get_skill(self): print('I hava a skill') class BasketballSkillMixin(SkillMixin): def __init__(self): super(BasketballSkillMixin,self).__init__() self.skill='basketball' def get_skill(self): print('I hava a %s skill'%self.skill) class FootballSkillMixin(SkillMixin): def __init__(self): super(FootballSkillMixin,self).__init__() self.skill='football' def get_skill(self): print('I hava a %s skill'%self.skill) class MyBasketStudent(BasketballSkillMixin,Student): def __init__(self,name,gender,score): Student.__init__(self,name,gender,score) BasketballSkillMixin.__init__(self) class MyFootballTeacher(FootballSkillMixin,Teacher): def __init__(self,name,gender,course): Teacher.__init__(self,name,gender,course) FootballSkillMixin.__init__(self) a=MyBasketStudent('xiaoming','man',98) print(a.who()) print(a.get_skill()) # b=MyFootballTeacher('lixing','man','physical') # print(b.who()) # print(b.get_skill())
疑问:为啥最后一行多打印了一个None?
print
(
'I hava a %s skill'
%
self
.skill)都改成return
'I hava a %s skill'
%
self
.skill。
或者
print
(a.get_skill())改成a.get_skill()直接运行,因为你定义的
def
get_skill(
self
):自带打印了。
参考下这个呢https://www.zhihu.com/question/434250863,可能是这个原因