Home  >  Article  >  Backend Development  >  What is inheritance in python

What is inheritance in python

藏色散人
藏色散人Original
2019-06-24 10:52:583564browse

What is inheritance in python

What is python inheritance?

Inheritance of python classes

Python is an interpreted, object-oriented, high-level programming language with dynamic data types.

One of the main features of object-oriented programming (OOP) languages ​​is "inheritance". Inheritance refers to the ability to use all the functionality of an existing class and extend it without having to rewrite the original class.

The new class created through inheritance is called "subclass" or "derived class", and the inherited class is called "base class", "parent class" or "super class". The process of inheritance is The process from general to special. In some OOP languages, a subclass can inherit from multiple base classes. But in general, a subclass can only have one base class. To achieve multiple inheritance, it can be achieved through multi-level inheritance.

There are two main types of implementation methods for the inheritance concept: Implementation inheritance and interface inheritance.

Implementation inheritance refers to the ability to use the properties and methods of a base class without additional coding.

Interface inheritance refers to using only the names of properties and methods, but the subclass must provide the ability to implement them (the subclass refactors the parent class method).

When considering using inheritance, one thing to note is that the relationship between two classes should be a "belongs to" relationship. For example, Employee is a person and Manager is also a person, so both classes can inherit the Person class. But the Leg class cannot inherit the Person class because the leg is not a person.

OO development paradigm is roughly as follows: dividing objects → abstract classes → organizing classes into hierarchical structures (inheritance and synthesis) → using classes and instances to design and implement several stages.

Related recommendations: "Python Tutorial"

The above is the detailed content of What is inheritance in python. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn