python 多继承的实现
生活随笔
收集整理的這篇文章主要介紹了
python 多继承的实现
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
第一類多繼承的實現(xiàn):
from Child import Child def main():c = Child(300, 100)print(c.money, c.faceValue)c.play()c.eat()#注意:父類中方法名相同,默認調(diào)用的是在括號中排前面的父類中的方法c.func() if __name__ == "__main__":main()第二類Mother:
class Mother(object):def __init__(self, faceValue):self.faceValue = faceValuedef eat(self):print("eat")def func(self):print("func2")第三類Father:
''' 學(xué)習(xí)中遇到問題沒人解答?小編創(chuàng)建了一個Python學(xué)習(xí)交流QQ群:725638078 尋找有志同道合的小伙伴,互幫互助,群里還有不錯的視頻學(xué)習(xí)教程和PDF電子書! ''' class Father(object):def __init__(self, money):self.money = moneydef play(self):print("play")def func(self):print("func1")第四類Child
from Father import Father from Mother import Motherclass Child(Father, Mother):def __init__(self, money, faceValue):#寫法Father.__init__(self, money)Mother.__init__(self, faceValue)結(jié)尾給大家推薦一個非常好的學(xué)習(xí)教程,希望對你學(xué)習(xí)Python有幫助!
Python基礎(chǔ)入門教程推薦:更多Python視頻教程-關(guān)注B站:Python學(xué)習(xí)者
https://www.bilibili.com/video/BV1LL4y1h7ny?share_source=copy_web
Python爬蟲案例教程推薦:更多Python視頻教程-關(guān)注B站:Python學(xué)習(xí)者
https://www.bilibili.com/video/BV1QZ4y1N7YA?share_source=copy_web
總結(jié)
以上是生活随笔為你收集整理的python 多继承的实现的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python 比较列表相邻元素(找相同或
- 下一篇: python 单继承的实现