Validation of Python's new class and Legacy class inheritance order

Source: Internet
Author: User
Tags class definition

Reference: http://www.cnblogs.com/blackmatrix/p/5630515.html

Official: https://docs.python.org/2/tutorial/classes.html

About multiple inheritance issues

Python supports a limited form of multiple inheritance as well. A class definition with multiple base classes looks like this:

For Old-style classes, the only rule is Depth-first, left-to-right. Thus, if an attribute was not found in derivedclassname, it was searched in Base1, then (recursively) in the base classes of Base1, and only if it's not found there, it's searched in Base2, and so on.

(To some people breadth first-searching Base2 and BASE3 before the base classes of base1-looks more natural. However, this would require-know whether a particular attribute of BASE1 is actually defined in Base1 or in one of Its base classes before your can figure out the consequences of a name conflict with an attribute of Base2. The Depth-first rule makes no differences between direct and inherited attributes of Base1.)

For New-style classes, the method resolution order changes dynamically to support cooperative calls to super (). This approach are known in some other multiple-inheritance languages as Call-next-method and are more powerful than the Supe R call found in Single-inheritance languages.

Test section

Please look here.

Above.

Validation of Python's new class and Legacy class inheritance order

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.