Python class and inheritance, inheritance is not quite understood, first put a piece of code

Source: Internet
Author: User

Python class and inheritance, the preliminary understanding, where the 12th line CALSS people () add no company is the same, this is not understood.

classCompany :def __init__(self,name,birthyear,birthmonth,birthplace): Self.name=name Self.birthyear=birthyear Self.birthmonth=Birthmonth Self.birthplace=Birthplacedefdesc (self):Print('%s was created in%d%d months and was born in {0}'. Format (self.birthplace)%(self.name,self.birthyear,self.birthmonth))Print('{ 0} was created in {1} year {2} month, born in {3}'. Format (self.name,self.birthyear,self.birthmonth,self.birthplace))Print(Self.name,'created in', Self.birthyear,'years', Self.birthmonth,'Month','Born in', Self.birthplace)classPeople (company):def __init__(self,name,birthday,birthmonth,birthplace): Company.__init__(Self,name,birthday,birthmonth,birthplace)defdesc (self):Print('{ 0} was born in {1} years {2} months, {3} people'. Format (Self.name, Self.birthyear, Self.birthmonth, Self.birthplace)) C=company ('Blog Park', 2004, 1,'Yangzhou, Jiangsu') C.desc () p=people ('Chen Duxiu', 1879, 10,'Anqing, Anhui') P.desc ()

Operation Result:

Founded in January 2004, the blog Park was born in Yangzhou, Jiangsu province.
Founded in January 2004, the blog Park was born in Yangzhou, Jiangsu province.
Founded in January 2004, the blog Park was born in Yangzhou, Jiangsu Province
Chen Duxiu was born in October 1879, Anhui anqing people

Back again to learn the post.

Python class and inheritance, inheritance is not quite understood, first put a piece of code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.