三大特性

來源:互聯網
上載者:User

標籤:__init__   存在   python類   層級   封裝   類型   同事   on()   ldb   

class oldboy:    def __init__(self,bk):        self.arg = bk        self.name = ‘alex‘    def func_1(self):        print(self.arg)        print(self.name)        return True    def func_2(self):        print(‘%s xx‘%self.arg)        return Trueobj = oldboy(‘妹子‘)obj.func_1()class oldgl:    def __init__(self,bk):        self.name = ‘alex‘        self.faver = bkobj= oldgl(‘bb‘)class vov:    def zou(self):        print(‘vov走‘)class yio(vov):    def zou(self):        print(‘yio走‘)class yie(vov):    def zou1(self):        print(‘yie走‘)class move(yio):    def zou4(self):        print(‘走‘)class imove(yie):    def zou2(self):        print(‘一起走‘)class people(imove,move):    def __init__(self,name,gender,height,weight):        self.Name = name        self.Gender = gender        self.Height = height        self.Weight = weight    def see(self):        self.Weight -= 10        print(self.Weight)        return self.Weight    def motion(self):        self.Weight += 20        return self.Weightmike = people(‘麥克‘,‘男‘,155,122)mike.see()mike.motion()mike.zou()a = move()mike.zou()‘‘‘三大特性 封裝 繼承 多態:封裝    使用情境:當同一類型的方法具有相同參數時,直接封裝到對象即可    使用情境:把類當作模版,建立多個對象(對象內封裝的資料可以)繼承    衍生類別可以繼承基類中所有功能    衍生類別和基類同事存在,優先找衍生類別    python類可以同時繼承多個類(c#/java不可以)————優先順序別,自己,左邊,右邊    多繼承規則—————  左1-2 → 右1-2 → 左3-4 → 右5-6  以此類推多態    多種形態    python本身支援多態    擴充:        重載,函數名相同,參數個數不同——————python不支援        重寫,衍生類別中重新實現基類的中的方法  ‘‘‘

  

三大特性

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.