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

為了賬號(hào)安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
  • 在定義繼承類的時(shí)候,有幾點(diǎn)是需要注意的:

    class Student()定義的時(shí)候,需要在括號(hào)內(nèi)寫明繼承的類Person

    在__init__()方法,需要調(diào)用super(Student, self).__init__(name, gender),來初始化從父類繼承過來的屬性

    查看全部
    0 采集 收起 來源:Python繼承類

    2021-04-30

  • #!/usr/bin/env?python
    #?coding:?utf-8
    """
    @author???ChenDehua?2021/4/22?19:31
    @note?????
    """
    import?time
    def?log(timeunit):
    
    ????def?wrapper(f):
    ????????def?inner_wrapper(*args,?**kwargs):
    ????????????print("current?timeunit?is?{}".format(timeunit))
    ????????????start?=?time.time()
    ????????????print("start?time?->?{}".format(start))
    ????????????result?=?f(*args,?**kwargs)
    ????????????time.sleep(1)
    ????????????end?=?time.time()
    ????????????print("end?time?->?{}?spend?time?:{}"
    ??????????????????.format(end,?end?-?start?if?timeunit?==?"s"?else?(end?*?1000)?-?(start?*?1000)))
    ????????????return?result
    
    ????????return?inner_wrapper
    ????return?wrapper
    
    
    @log("ms")
    def?register_student(name,age,**kwargs):
    ????print("register_student?-->?name:{}?age:{}?additional?info:{}"
    ??????????.format(name,?age,?"".join(["{}:{}??".format(key,?value)?for?key,value?in?kwargs.items()])))
    
    
    if?__name__?==?"__main__":
    ????register_student("chendehua",?21,?class_no=1800502108,?school="gdpu")
    查看全部
  • print([item?for?item?in?sorted(['bob',?'about',?'Zoo',?'Credit'],?key=lambda?value:value[0].lower())])

    一行代碼搞定

    查看全部
  • 一行搞定:

    print([item?for?item?in?filter(lambda?x:int(math.sqrt(x))?*?int(math.sqrt(x))==?x,?[i?for?i?in?range(1,100)])])
    查看全部
  • if?__name__?==?"__main__":
    ????with?open("file.txt",?'a+')?as?file:
    ????????file.seek(0)
    ????????lines?=?file.readlines()
    ????????file.write("\n")
    ????????for?line?in?lines:
    ????????????file.write(line)
    查看全部
  • if?__name__?==?"__main__":
    ????file?=?open("file.txt",?"r")
    ????line2?=?file.readlines()
    
    ????new_file?=?open("file1.txt",?'w')
    ????for?index,?line?in?enumerate(line2):
    
    ????????line?=?line[-2::-1]?if?index?!=?len(line2)?-?1?else?line[::-1]
    ????????new_file.write(line?+?"\n"?if?index?!=?len(line2)?-?1?else?line)
    
    ????new_file.close()
    ????file.close()

    這才是正確答案

    查看全部
  • 例子:運(yùn)行時(shí)導(dǎo)入上級(jí)目錄的模塊

    if __name__ == "__main__":
    ? ?import sys
    ? ?sys.path.append("../")
    ? ?import hello
    ? ?hello.say_hello()

    查看全部
  • 關(guān)于多重繼承,需要徹底弄懂!

    有如下繼承關(guān)系:

    class A:
    ? ?def __init__(self, msg):
    ? ? ? ?print("init A..", msg)

    class B(A):
    ? ?def __init__(self, msg):
    ? ? ? ?super(B, self).__init__(msg)
    ? ? ? ?print("init B..", msg)

    class C(A):
    ? ?def __init__(self, msg):
    ? ? ? ?super(C, self).__init__(msg)
    ? ? ? ?print("init C..", msg)

    class D1(C):
    ? ?def __init__(self, msg):
    ? ? ? ?super(D1, self).__init__(msg)
    ? ? ? ?print("init D1..", msg)

    class D(C,B):
    ? ?def __init__(self, msg):
    ? ? ? ?super(D, self).__init__(msg)
    ? ? ? ?print("init D..", msg)

    class Zero:
    ? ?def __init__(self, msg):
    ? ? ? ?print("init Zero", msg)

    class One(Zero):
    ? ?def __init__(self, msg):
    ? ? ? ?super(One, self).__init__(msg)
    ? ? ? ?print("init One", msg)

    class E(One, C):
    ? ?def __init__(self):
    ? ? ? ?super(C, self).__init__("ddd")class E(One, C):
    ? ?def __init__(self):
    ? ? ? ?super(C, self).__init__("ddd")

    super(C, self).__init__("ddd")的意思是找類C的父類(類A)

    ddd作為類A的msg:

    e = E()

    只輸出init A.. ddd

    如果是super(One, self).__init__("ddd"),代表找One的父類(Zero),輸出init Zero ddd(super(One,self)只是找One的父類,并不會(huì)執(zhí)行One的init方法)

    如果是super(E, self).__init__("ddd"),則會(huì)輸出

    init Zero ddd
    init One ddd

    找E的父類,此時(shí)因?yàn)镋是多重繼承,繼承了One,和C,此時(shí)super(E,self)就會(huì)選擇第一個(gè)類One,而不會(huì)去找C

    還有一種情況就是菱形繼承:

    class Base(object):
    ? ?def __init__(self):
    ? ? ? ?print("enter Base")
    ? ? ? ?print("leave Base")

    class A(Base):
    ? ?def __init__(self):
    ? ? ? ?print("enter A")
    ? ? ? ?super(A, self).__init__()
    ? ? ? ?print("leave A")

    class B(Base):
    ? ?def __init__(self):
    ? ? ? ?print("enter B")
    ? ? ? ?super(B, self).__init__()
    ? ? ? ?print("leave B")

    class C(A, B):
    ? ?def __init__(self):
    ? ? ? ?print("enter C")
    ? ? ? ?super(C, self).__init__()
    ? ? ? ?print("leave C")

    if __name__ == "__main__":
    ? ?c = C()

    輸出:

    enter C
    enter A
    enter B
    enter Base
    leave Base
    leave B
    leave A
    leave C

    看看c的mro就知道調(diào)用順序了

    >>> C.mro() ? # or C.__mro__ or C().__class__.mro()
    [__main__.C, __main__.A, __main__.B, __main__.Base, object]

    不存在菱形繼承問題的時(shí)候(第一種情況),就可以手動(dòng)指定需要去調(diào)用哪一個(gè)類的父類,如果父類是多重繼承的,就取第一個(gè)類。

    class A:
    ? ?def __init__(self, msg):
    ? ? ? ?print("init A..", msg)
    class C(A):
    ? ?def __init__(self, msg):
    ? ? ? ?super(C, self).__init__(msg)
    ? ? ? ?print("init C..", msg)
    class Zero:
    ? ?def __init__(self, msg):
    ? ? ? ?print("init Zero", msg)
    class Zero1:
    ? ?def __init__(self, msg):
    ? ? ? ?print("init Zero1", msg)

    class One(Zero, Zero1):
    ? ?def __init__(self, msg):
    ? ? ? ?super(One, self).__init__(msg)
    ? ? ? ?print("init One", msg)

    class E(One, C):
    ? ?def __init__(self):
    ? ? ? ?# super(E, self).__init__("ddd")
    ? ? ? ?super(One, self).__init__("ddd")

    if __name__ == "__main__":
    ? ?e = E()

    所以,super可以調(diào)用多次,來選擇不同父類的init方法

    第二種情況,菱形問題的時(shí)候,就需要用到mro,來決定調(diào)用順序

    查看全部
  • class Animal(object):

    ? ? def __init__(self, name, age):#初始化

    ? ? ? ? self.name=name

    ? ? ? ? self.age=age

    dog=Animal("曦曦",10)

    cat=Animal("歡歡",9)

    print(dog.name,dog.age)

    查看全部
  • 測試
    查看全部
  • 在定義繼承類的時(shí)候,有幾點(diǎn)是需要注意的:

    class Student()定義的時(shí)候,需要在括號(hào)內(nèi)寫明繼承的類Person

    在__init__()方法,需要調(diào)用super(Student, self).__init__(name, gender),來初始化從父類繼承過來的屬性

    查看全部
    0 采集 收起 來源:Python繼承類

    2021-04-02

  • 在類屬性和實(shí)例屬性同時(shí)存在的情況下,實(shí)例屬性的優(yōu)先級(jí)是要高于類屬性的,在操作實(shí)例的時(shí)候,優(yōu)先是操作實(shí)例的屬性。

    可見通過實(shí)例是無法修改類的屬性的,事實(shí)上,通過實(shí)例方法修改類屬性,只是給實(shí)例綁定了一個(gè)對(duì)應(yīng)的實(shí)例屬性。

    查看全部
  • r1 = Rational(1, 2) 第一個(gè)數(shù)是1/2

    r2 = Rational(1, 5) 第二個(gè)數(shù)是1/5

    查看全部

舉報(bào)

0/150
提交
取消
課程須知
本課程是Python入門的后續(xù)課程 1、掌握Python編程的基礎(chǔ)知識(shí) 2、掌握Python函數(shù)的編寫 3、對(duì)面向?qū)ο缶幊逃兴私飧?/dd>
老師告訴你能學(xué)到什么?
1、什么是函數(shù)式編程 2、Python的函數(shù)式編程特點(diǎn) 3、Python的模塊 4、Python面向?qū)ο缶幊?5、Python強(qiáng)大的定制類

微信掃碼,參與3人拼團(tuán)

微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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

友情提示:

您好,此課程屬于遷移課程,您已購買該課程,無需重復(fù)購買,感謝您對(duì)慕課網(wǎng)的支持!