Object-Oriented Programming Summary-Python,-python
All things are objects. The natural environment gives us endless imagination, and the idea of object-oriented programming comes from nature. In nature, classes and objects are everywhere. For example: birds and sparrows, fish and carp ...... birds are the generic names of various birds, while sparrows are only one of them (objects ).
What is process-oriented? What Is Object-Oriented?This is one of the "Contradictions" in the programming world. In fact, I am also dumb to find out... I can only take a drink to "Open the knife ". Oh, it's not an example.
Object-oriented:
Liquor is a kind of everyday life drink, liquor is an abstract class, Moutai is the specific object of wine, and cheers is the implementation method of drinking.
Class Drinking_wine (object ):
Def _ init _ (self, name ):
Self. name = name
Def drinking ():
Pick up wine bottle
Unscrew the wine cap
Pour wine
Drinking
Then call the class (Drinking_wine ()):
Maotai = Drinking_wine ('mouta') shuijingfang = Drinking_wine ('shuijingfang ') maotai. drinking () shuijingfang. drinking ()
Process-oriented:
Pick up the wine bottle on the table-> unscrew the wine lid-> take out the wine glass-> pour out the wine-> pick up the wine glass-> mouth out "bro, cheers !" -> Touch the glass.-> just drink it.
Def Drinking_wine ():
Pick up wine bottle
Unscrew the wine cap
Pour wine
Drinking
Object-Oriented Programming-Object Oriented Programming, or OOP for short, uses objects as the basic unit of a program. An Object contains functions of data and operation data. It is a program design idea.
In Python, all data types (including custom objects) can be considered objects. Data types can be identified by type. For example:
A = 4
Type ()
<Class 'int'>
Figure 1 type usage example
Specifically, in the Python programming environment, the Data Type of a custom object is the class in the object-oriented environment. Therefore, the design idea of object-oriented programming is to abstract the Class, and then create an instance based on the Class, and then the instance
Call a function.
Object-Oriented Programming is summarized as follows:
1. The degree of object-oriented abstraction is higher than that of functions, because a Class contains both data and operation data.
2. Three main features: inheritance, polymorphism, and Data encapsulation
3. Understand the differences between object-oriented and process-oriented