Oldboy Twentieth Day. I Love Python. Object-Oriented inheritance:

Source: Internet
Author: User

Inheritance: Subclasses (derived classes) inherit everything from the parent class (the base class)
The most important feature of inheritance: Save code; associated with other classes.
Why can subclasses find all of the parent classes?
Because the concept of a parent class pointer exists
Categories of inheritance:
1, Version Category:
python3.x:
class inherits the object class by default, and the class that inherits the object class is called the new class
python2.x:
Class is not inherited by default, and classes that do not inherit object are called Classic classes. If you let him inherit the object class in python2.x, it becomes a new class.
2, according to the classification of inheritance:
Single inheritance: Query order always up (new class, classic Class)
Methods for inheriting a parent class in a subclass: 1, object.__init__ (self, *args); 2, Super (). __init__ (*args)
Multiple inheritance:
New class: Breadth-first and breadth algorithms: walk through each node with the fewest number of times, each node, and only once Object.mro () find the inheritance order.
Classic class: Depth first: One way to the black.

Oldboy Twentieth Day. I Love Python. Object-Oriented inheritance:

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.