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

麻烦大神看一下,为什么代码运行后显示Skill不存在?(已解决)

class Person(object):

    def __init__(self, name, age):

        self.name = name

        self.age = age

class Student(Person):

    def __init__(self, name, age, grade):

        super(Student, self).__init__(name, age)

        self.grade = grade

class Teacher(Person):

    def __init__(self, name, age, subject):

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

        self.subject = subject

class Skill(object):

    def __init__(self,skill):

        self.skill = skill

class Basketball(Skill):

    def __init__(self,skill, level):

        super(Basketball, self).__init__(skill)

        self.level = level

class Football(Skill):

    def __init__(self,skill,level):

        super(Football, self).__init__(skill)

        self.level=level

class BK(Student,Basketball):

    def __init__(self,name,age,grade,skill,level,practise_time):

      Student.__init__(self,name, age, grade)

      Basketball.__init__(self, skill, level)

 #  super(BK,self).__init__(name,age,grade,skill,level)(原来是这样写的,外部调用不了第二父类的属性)

        BK.practise_time=practise_time

class FT(Teacher,Football):

    def __init__(self,name,age,subject,skill,level,practise_time):

       Teacher.__init__(self,name,age,subject)

       Football.__init__(self,skill,level)

# super(FT,self).__init__(name,age,subject,skill,level)

        FT.practise_time = practise_time

a = BK('LiMing', 13, 13,'Basketball', 3, 6)

b = FT('LiLei', 40, 'Math', 'Football',6,20)

print(a.age)

print(b.skill)


正在回答

2 回答

外部调用不了第二父类的属性,醍醐灌顶!

0 回复 有任何疑惑可以回复我~

代码可以运行,要注意class BK和class FT这两个类里面__init__()方法代码的空格,空格要统一

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

麻烦大神看一下,为什么代码运行后显示Skill不存在?(已解决)

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