为了账号安全,请及时绑定邮箱和手机立即绑定

不知道哪里错了,请大神指导

class Person:
    def __init__(self,name,gender):
        self.name=name
        self.gender=gender
class Student(Person):
    def __init__(self,name,gender,score):
        super(Student, self).__init__(name,gender)
        self.score=score

class Teacher(Person):
    def __init__(self,name,gender,subject):
        super(Teacher, self).__init__(name, gender)
        self.subject=subject

class SkillMixin:
    def __init__(self,skill):
        self.skill=skill
class BasketballMixin(SkillMixin):
    def __init__(self,skill,basketball):
        super(BasketballMixin, self).__init__(skill)
        self.basketball=basketball

class FootballMixin(SkillMixin):
    def __init__(self,skill,football):
        super(FootballMixin, self).__init__(skill)
        self.football=football

class BasStudent(Student,BasketballMixin):
    def __init__(self,name,gender,score,skill,basketball):
        super(BasStudent, self).__init__(name,gender,score)
    def getskill(self):
        print("我叫 %s,我会打%s "%(self.name,self.basketball))
a=Student('jiji','boy',13)
b=BasketballMixin('high','篮球',)
c=BasStudent.getskill()
print(c)


正在回答

1 回答

class BasStudent(Student,BasketballMixin):

    def __init__(self,name,gender,score,skill,basketball):

        super(BasStudent, self).__init__(name,gender,score)

    def getskill(n,k):

        print("我叫 %s,我会打%s "%(n,k))

a=Student('jiji','boy',13)

b=BasketballMixin('high','篮球',)

c=BasStudent.getskill(a.name,b.basketball)


--我改成这个样子,好像能得到题主想要的结果。其原因在于如果用getskill(self),因为有两个父类,self无法区分(或者我还不知道该怎样区分)student或basketballmixin。然后我就偷懒这样改了。😀

下载视频          
0 回复 有任何疑惑可以回复我~
#1

高飞的鱼 提问者

用这个方法,执行正确吗?要是不用get方法呢,可以吗
2022-03-07 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

不知道哪里错了,请大神指导

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信