Python multiple inheritance and MRO-C3 algorithm

Source: Internet
Author: User

Inheritance diagram:

breadth-First traversal : First find A, then find B, C, and finally find D, E. (Order: A, B, C)

Depth-First traversal: first find A, then look for B, and then find D, E (find the B inside), and then find C. (Order: A, B, D, E, C)

MRO-C3 Search:

>>> class D:    name = ' d '  >>> class E:    pass>>> class C:    name = ' C '  >> > class B (d,e):  #继承多个父类, such as: Genetics of Father and mother.    pass>>> class A (b,c):  #继承多个类, such as: Father and mother will eat, but everyone eat different way, see how genetic    pass>>> print (a.name)  #类A继承了B类和C类, it will first go to Class B (Class B inherits Class D and E) inside, find the result is pass, and then go to Class B inside the Class D to find, the result with the name attribute.

  

Python multiple inheritance and MRO-C3 algorithm

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.