python中類和繼承,繼承還不太瞭解,先貼一段代碼

來源:互聯網
上載者:User

標籤:def   any   day   print   people   format   ini   form   一段   

python中的類和繼承,初步認識,其中第12行calss people()中加不加company都是一樣的,這點還不瞭解.

class company:    def __init__(self,name,birthyear,birthmonth,birthplace):        self.name=name        self.birthyear=birthyear        self.birthmonth=birthmonth        self.birthplace=birthplace    def desc(self):        print(‘%s建立於%d年%d月,誕生於{0}‘.format(self.birthplace)%(self.name,self.birthyear,self.birthmonth))        print(‘{0}建立於{1}年{2}月,誕生於{3}‘.format(self.name,self.birthyear,self.birthmonth,self.birthplace))        print(self.name,‘建立於‘,self.birthyear,‘年‘,self.birthmonth,‘月‘,‘誕生於‘,self.birthplace)class people(company):    def __init__(self,name,birthday,birthmonth,birthplace):        company.__init__(self,name,birthday,birthmonth,birthplace)    def desc(self):        print(‘{0}出生於{1}年{2}月,{3}人‘.format(self.name, self.birthyear, self.birthmonth, self.birthplace))c=company(‘部落格園‘,2004,1,‘江蘇揚州‘)c.desc()p=people(‘陳獨秀‘,1879,10,‘安徽安慶‘)p.desc()

運行結果:

部落格園建立於2004年1月,誕生於江蘇揚州
部落格園建立於2004年1月,誕生於江蘇揚州
部落格園 建立於 2004 年 1 月 誕生於 江蘇揚州
陳獨秀出生於1879年10月,安徽安慶人

後面再學了再貼.

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.