日本综合一区二区|亚洲中文天堂综合|日韩欧美自拍一区|男女精品天堂一区|欧美自拍第6页亚洲成人精品一区|亚洲黄色天堂一区二区成人|超碰91偷拍第一页|日韩av夜夜嗨中文字幕|久久蜜综合视频官网|精美人妻一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
創(chuàng)新互聯(lián)Python教程:Pythonsuper()

內(nèi)置函數(shù)super()有助于 python 中的繼承。該函數(shù)返回一個(gè)表示父類的對(duì)象,并允許訪問父類的方法和屬性。

創(chuàng)新互聯(lián)建站服務(wù)項(xiàng)目包括三門網(wǎng)站建設(shè)、三門網(wǎng)站制作、三門網(wǎng)頁制作以及三門網(wǎng)絡(luò)營(yíng)銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢(shì)、行業(yè)經(jīng)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,三門網(wǎng)站推廣取得了明顯的社會(huì)效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到三門省份的部分城市,未來相信會(huì)繼續(xù)擴(kuò)大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!

 **super()** 

超級(jí)()參數(shù):

它不需要任何參數(shù)。這個(gè)方法可以處理多個(gè)繼承,并且它避免了顯式使用基類名稱。

超級(jí)()返回值

此方法不返回任何內(nèi)容。在 python 中,方法解析順序(MRO)概述了方法的繼承順序。派生調(diào)用中的方法總是在基類的方法之前調(diào)用。

Python 中super()方法的示例

示例 1:單繼承的super()在 python 中是如何工作的

 class Mammals(object):
  def __init__(self, mammalName):
    print(mammalName, 'is a pet animal.')

class Cat(Mammals):
  def __init__Cat has four legs.')
    super().__init__('Cat')

c = Cat() 

輸出:

Cat is a pet animal.

示例 2:如何在 python 中使用多重繼承的super()

 class Animals:
  def __init__(self, Animals):
    print(Animals, 'is an animal.');

class Mammals(Animals):
  def __init__(self, mammalName):
    print(mammalName, 'is a pet animal.')
    super().__init__(mammalName)

class NonWingedMammal(Mammals):
  def __init__(self, NonWingedMammal):
    print(NonWingedMammal, "can't fly.")
    super().__init__(NonWingedMammal)

class NonMarineMammal(Mammals):
  def __init__(self, NonMarineMammal):
    print(NonMarineMammal, "can't swim.")
    super().__init__(NonMarineMammal)

class Cat(NonMarineMammal, NonWingedMammal):
  def __init__(self):
    print('Cat has 4 legs.');
    super().__init__('Cat')

c = Cat()
print('')
bat = NonMarineMammal('Bat') 

輸出:

Cat has 4 legs.
Cat can't swim.
Cat can't fly.
Cat is a pet animal.
Cat is an animal.

Bat can't swim.
Bat is a pet animal.
Bat is an animal. 

分享文章:創(chuàng)新互聯(lián)Python教程:Pythonsuper()
文章來源:http://www.dlmjj.cn/article/dpccphs.html