Home  >  Article  >  Backend Development  >  Is python object-oriented or process-oriented?

Is python object-oriented or process-oriented?

王林
王林Original
2020-04-07 14:06:194761browse

Is python object-oriented or process-oriented?

#Although Python is an interpreted language, it has been an object-oriented language from the beginning of its design. For Python, everything is an object. Because of this, it is very easy to create a class and object in Python. Of course, if you are accustomed to process-oriented or function-oriented writing, it is also possible. Python does not impose hard restrictions.

Python’s object-oriented features are as follows:

Encapsulation

The term object (Object) in object-oriented programming can basically be regarded as data (properties) and a series of A collection of methods that can access and manipulate this data. The traditional "program = data structure algorithm" is encapsulated, "covered" and simplified to "program = object message". Objects are instances of classes, and the abstraction of classes needs to be encapsulated. Encapsulation allows the caller to use the object directly without caring about how the object is constructed.

(Video tutorial recommendation: python video tutorial)

Inheritance

Class inheritance:

The direct feeling of inheritance is This is an act of reusing code. Inheritance can be understood as establishing a special class object based on an ordinary class. The subclass has an IS-A relationship with the parent class it inherits.

Multiple inheritance:

Unlike C#, Python supports multiple class inheritance (C# can inherit from multiple Interfaces, but can inherit from one class at most). The multiple inheritance mechanism is sometimes useful, but it can easily complicate things.

Polymorphism

Polymorphism means that the same operation can be used on different objects, but they may present results in multiple forms. In Python, polymorphism is used whenever you don't know what type an object is, but you need the object to do something. Methods are polymorphic and so are operators.

Recommended related tutorials: python tutorial

The above is the detailed content of Is python object-oriented or process-oriented?. 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