第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定

多重繼承問題:super中傳一個多重繼承的類,只能識別到第一個

問題描述:
B繼承A,Y繼承Z,BY繼承B和Y,那么BY中的super只能代表B(如果是YB則只能代表Y),希望是可以super可以代表BY,代碼如下:
class SkillMixin(object):
def?init(self,skillName):
self.skillName = skillName
class BasketballMixin(SkillMixin):
def?init(self,skillName):
super(BasketballMixin,self).init(skillName)

class Person(object):
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 BasketballStudent(Student,BasketballMixin,):
def?init(self,name,gender,score,skillName):
super(BasketballStudent,self).init(name,gender,score,skillName)

bs = BasketballStudent('basketboy','man',59,'basketball')
print(bs.name,bs.skillName)


正在回答

3 回答

class Person:

? ? def __init__(self, name, gender):

? ? ? ? self.name = name

? ? ? ? self.gender = gender


class SkillMixin:

? ? def __init__(self, skill):

? ? ? ? self.skill = skill

? ? def say(self):

? ? ? ? print("技能是 %s" %(self.skill))


class BasketballMixin(SkillMixin):

? ? def __init__(self, skill):

? ? ? ? super(BasketballMixin, self).__init__(skill)


class Student(Person, BasketballMixin):

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

? ? ? ? super(Student, self).__init__(name, gender)

? ? ? ? BasketballMixin.__init__(self, skill)

? ? ? ? self.score = score

? ? def say(self):

? ? ? ? print("學(xué)生叫%s,現(xiàn)在讀%s,考試分?jǐn)?shù)為%d, 喜歡%s" %(self.name, self.gender, self.score, self.skill))

? ? ? ?

class Teacher(Person):

? ? def __init__(self, name, gender, subject):

? ? ? ? super(Teacher, self).__init__(name, gender)

? ? ? ? self.subject = subject

? ? def say(self):

? ? ? ? print("老師叫{},現(xiàn)在在{}教{}。".format(self.name, self.gender, self.subject))


t = Teacher('xx', '一年級', '數(shù)學(xué)')

s = Student('小明', '一年級', 99, '籃球')

# t.say()

s.say()



0 回復(fù) 有任何疑惑可以回復(fù)我~

class Person(object):
??? def __init__(self):
??????? print("I am person")
?????? ?
class Student(Person):
??? def __init__(self):
??????? super(Student,self).__init__()
??????? print("i am student")
??????? self.name = 'Andy'
?????? ?
?????? ?
class SkillMixin(object):
??? def __init__(self):
??????? print("i can skill")


class BasketballMixin(SkillMixin):
??? def __init__(self):
??????? super(BasketballMixin,self).__init__()
??????? print("i can basketball")
??????? self.ball = "basketball"
?????? ?

?????? ?
?????? ?
class BasketballStudent(Student,BasketballMixin):
??? def __init__(self):
??????? super(BasketballStudent,self).__init__()
??????? print("student can basketball")
?????? ?
stu = BasketballStudent()

print(stu.name)

print(stu.ball)


打印姓名沒問題,打印球就報錯,很好的說明了這個問題

0 回復(fù) 有任何疑惑可以回復(fù)我~

我也發(fā)現(xiàn)這個問題,多重繼承好像是個笑話,本質(zhì)上還是只繼承了第一個

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消

多重繼承問題:super中傳一個多重繼承的類,只能識別到第一個

我要回答 關(guān)注問題
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號