Object-Oriented Programming Summary-Python,-python

Source: Internet
Author: User

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

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.