日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

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

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Python教程:python中super的使用注意

1、SUPER()只能用于新式類中

所謂新式類,舊類的,關鍵就是看是不是有基類,有基類的就是形式類,比如class A(object),所以class A()自然就是舊式類了。

# 單繼承
class A(object):
 
    def __init__(self, a, b):
        self.a = a
        self.b = b
 
    def sayHello(self):
        print('this is class A, a={},b={}'.format(self.a, self.b))
 
class B(A):
 
    def __init__(self, a, b, c):
        super(B, self).__init__(a,b)
        self.c = c
 
    def sayHello(self):
        super(B, self).sayHello()
        print('this is b call')
 
b = B('b','also b','test')
b.sayHello()
# this is class A, a=b,b=also b
# this is b call

2、super 其實和父類沒有實質性的關聯(lián)

多重繼承下,super就沒有那么簡單了。

# 多重繼承
 
class Base(object):
    def __init__(self):
        print('enter Base')
        print('out Base')
class A(Base):
    def __init__(self):
        print('enter A')
        super(A, self).__init__()
        print('out A')
class B(Base):
    def __init__(self):
        print('enter B')
        super(B, self).__init__()
        print('out B')
class C(A, B):
    def __init__(self):
        print('enter C')
        super(C, self).__init__()
        print('out C')
 
c = C()
#enter C
#enter A
#enter B
#enter Base
#out Base
#out B
#out A
#out C

以上就是python中super的使用注意,希望能對大家有所幫助。更多Python學習指路:創(chuàng)新互聯(lián)python教程

本文教程操作環(huán)境:windows7系統(tǒng)、Python 3.9.1,DELL G3電腦。


文章題目:創(chuàng)新互聯(lián)Python教程:python中super的使用注意
當前網(wǎng)址:http://m.5511xx.com/article/dhhpjpc.html