current position:Home>Introduction to Python [preliminary knowledge] - programming idea

Introduction to Python [preliminary knowledge] - programming idea

2022-05-15 04:07:25Inter personal liabilities^

Python It belongs to both object-oriented and process oriented programming language

1. Broad object-oriented concept

Process oriented

It can be seen literally , Object oriented focuses on the process , such as C、C++, Are classic process oriented programming languages .
If you've played a programming contest, you'll know , Programming competitions are like the Blue Bridge Cup 、ACM、ICPC etc. , Algorithm topics are process oriented , Pay attention to how you want to solve this algorithm problem .
Object oriented means , When dealing with one thing , We have to think about it all , From a to Z , And intermediate process .
such as :

Xiao Ming's Day : Xiao Ming had dinner in the morning - Xiao Ming has lunch - Xiao Ming slept at noon - Xiao Ming knocked the code in the afternoon - Xiao Ming had dinner in the evening - Xiao Ming slept at night


object , Did you learn java Should know , Everything is object ,Python equally , stay Python Everything in the world is also an object
Object-oriented programming ideas , For one thing , We don't need to consider the intermediate process of this matter , Just consider its object
such as :

Xiao Ming's Day : Xiao Ming lived all day

As can be seen from the above , The object-oriented programming language Freund is simpler than the process oriented programming language , This is also Python A simple aspect , Most programmers believe that object-oriented programming is simpler , Write more clearly .( Personally feel , Process oriented programming language is simpler … Maybe it's the sequelae of playing too much in the competition )

2. Python Object orientation in


class : Describe a type of transaction , An abstract concept , such as : people 、 animal 、 Fruits


object : A concrete representation of a class , such as : Zhang San 、 Li Si , cat 、 Dog , Apple 、 Banana


attribute : Characteristics of the object , such as : male 、 The woman , Big cat 、 puppy , Red apple 、 Green banana


Method : The functional behavior of the object , such as : Zhang Sanhui martial arts 、 Li Si can dance , Cats can catch mice 、 Dogs bark …

class - object - attribute
class - object - Method

3. Python Three characteristics of object-oriented in


Encapsulate properties and methods into an abstract class

External use class establish object , And then let object Calling method
The details of object methods are encapsulated inside the class


Single inheritance
Transitivity of code : Grandfather type methods can be used in grandchildren ( A son inherits his father's work )

Multiple inheritance
A subclass can inherit more than one parent class
The subclass has all the properties and methods of the parent class

Method rewriting : Write a method with the same name as the parent class in the subclass
characteristic : Call a method in a class , If found in subclasses , Directly execute the methods in the subclass , If this method is not found in the subclass , Just look in the parent class , Once found, call the method in the parent class , If... Is not found in the parent class , Just report a mistake


Multiple forms of an object ( One father and many children )
effect : Increase the flexibility of your code 、 Improve the extensibility of the code
Conditions : Inherit 、 Method rewrite

encapsulation 、 Inherit 、 Polymorphism is Python Three characteristics of
These three characteristics are java Also mentioned in , Did you learn java It wouldn't be so strange

4. Design of object-oriented programming

Inheritance system design What kind What are the attributes Encapsulated in what method

such as : door lock people , The way to open and close the door Encapsulated in whose class ?
Encapsulated in the class of the door ,( Whoever owns the data has the right to operate the data ) And a person is equivalent to main Method
Invocation time : Get the door object , Call the door opening and closing method

copyright notice
author[Inter personal liabilities^],Please bring the original link to reprint, thank you.

Random recommended