Home  >  Article  >  Backend Development  >  Why is Python object-oriented?

Why is Python object-oriented?

藏色散人
藏色散人Original
2019-07-01 09:21:053760browse

Why is Python object-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 used to process-oriented or function-oriented writing, it is also possible. Python does not impose hard restrictions.

  The object-oriented features of Python are as follows:

Encapsulation

The term object (Object) in object-oriented programming is basically It can be seen as a collection of data (features) and a series of methods that can access and operate these 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.

  Inheritance

Class inheritance:

The direct feeling of inheritance is that it is a behavior 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 at most one class). 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.

Related recommendations: "Python Tutorial"

The above is the detailed content of Why is Python object-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