Child class execution Parent class constructor method

Source: Internet
Author: User
  • Subclasses sometimes need to execute the parent class's constructor method
Class Annimal (object):    def __init__ (self):        print (' bar ')        self.type = ' Animal ' class Shengwu (object):    def _ _init__ (self):        print (' Sengwu ')        self.tc = ' Creature ' class Cat (Annimal,shengwu):        def __init__ (self):            SELF.N = ' Mao '            Super (cat,self). __init__ () m = Cat () print (m.__dict__)

The Cat class inherits the Annimal class and the Shengwu class, and in the construction method of the Cat class executes the construction method of the parent class super (cat,self). __init__ (), so the result:

However, the execution of the parent class is constructed by simply executing the Annimal __init__ () method, which does not implement the Shegnwu constructor method. This is identical to the order in which the inherited parent class executes the method in the parent class.

Child class execution Parent class constructor method

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.