Python3 The base super layer calls the parent class's __init__ method The __init__ of the subclass overrides the __init__ resolution of the parent class

Source: Internet
Author: User

Town Field Poem:
Cheng listens to the Tathagata language, the world name and benefit of Dayton. Be willing to do the Tibetan apostles, the broad show is by Sanfu mention.
I would like to do what I learned, to achieve a conscience blog. May all the Yimeimei, reproduce the wisdom of the body.
——————————————————————————————————————————
EX1:
Code

Class Parent:    def __init__ (self): #父类的构造函数        Print ("The parent class is constructed") class Child1 (parent): #child类继承于 The parent class    def __ Init__ (self):         print ("Subclass 1 Generation Constructor") class Child2 (Child1): #child类继承于    The parent def __init__ (self):         print (" Subclass 2-generation constructor ") Test=child2 ();  #父类的构造函数不会出现, the constructors for the subclass 1 generation do not appear


Result

EX2:

Code

Class Parent:    def __init__ (self): #父类的构造函数        Print ("The parent class is constructed") class Child1 (parent): #child类继承于 The parent class    def __ Init__ (self):        print ("Subclass 1 Generation Constructor") class Child2 (Child1): #child类继承于 The parent    def __init__ (self):        super (). __ init__ ()        print ("Subclass 2-generation constructor") Test=child2 ();  

  

Result

EX3:

Code

Class Parent:    def __init__ (self): #父类的构造函数        Print ("The parent class is constructed") class Child1 (parent): #child类继承于 The parent class    def __ Init__ (self):        super (). __init__ ()        print ("Subclass 1-generation constructor") class Child2 (Child1): #child类继承于 The parent class    def __init_ _ (Self):        super (). __init__ ()        print ("Subclass 2-generation constructor") Test=child2 ();    #每一级都有super才好呢

 

Result


——————————————————————————————————————————
The essence of the blog, in the technical part, more in the town yard a poem. Python version 3.5, System Windows7.
Python is a good language and deserves to be studied hard. I am following the small Turtle Video tutorial to learn, recommended.
I am a novice, so if the content of the blog can be improved, or even the wrong place, please leave a comment, I will try to correct, strive to achieve a conscience blog.
Note: This article is only as a scientific research study, if I inadvertently violated your rights and interests, please be sure to timely inform, I will make corrections.

Python3 The base super layer calls the parent class's __init__ method The __init__ of the subclass overrides the __init__ resolution of the parent class

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.