What is object-oriented in python

Focus on solving problems with object-oriented thinking

When you encounter a requirement, you don't need to implement it yourself. If you implement it step by step, it is process-oriented; you should find someone who specializes in doing it.

Object-oriented (object-oriented; abbreviation: OO) There is no unified concept so far. We can define it as: according to people's systematic thinking way of understanding the objective world, using the concept of object (entity) to build a model, simulate the analysis of the objective world, Ways to design and implement software.

Object Oriented Programming (OOP) is a design and programming method to solve software reuse. This method describes the similar operating logic and operating application data and status in the software system in the form of classes, and reuses them in the software system in the form of object instances to achieve the effect of improving the efficiency of software development.

The concept of classes and objects

class

Class is a general term for a group of things with the same characteristics or behaviors. It is abstract and cannot be used directly;

Features are called attributes;

Behaviors are called methods.

Object

An object is a concrete existence created by a class and can be used directly;

An object created by which class has the properties and methods defined in that class;

The relationship between class and object

A class is a template for creating objects. There should be a class first and then an object;

A class can create multiple objects, and the properties of different objects may be different;

What methods are defined in the class, and what attributes and methods are there in the object. It is impossible to be less, but there may be more, because the object can add properties outside the class by itself

Define a simple class

Object-oriented is a larger encapsulation, encapsulating multiple methods in a class, so that objects created by this class can directly call these methods.

Define a class that only contains methods

Define a class that only contains methods in python Chinese medicine. The syntax format is as follows:

class class name:
 def method 1(self,List parameter):
 pass
 def method 2(self,List parameter):
 pass

The definition format of the method is almost the same as the function learned before;

The difference is that the first parameter must be self;

Note that the naming rules for class names must conform to the big hump naming method;

Create object

When a class is defined, use this class to create objects. The syntax is as follows:

Object variable=Class name()

The first object-oriented program

classCat:"""Define a cat"""
 def eat(self):print("Kittens love to eat fish")

 def drink(self):print("Kitten wants to drink water")
    
tom =Cat()
tom.eat()
tom.drink()

Knowledge point expansion:

The relationship between object-oriented design and object-oriented programming

Object-oriented design (OOD) does not specifically require object-oriented programming languages. In fact, OOD can be implemented by a purely structured language, such as C, but if you want to construct a data type with object properties and characteristics, you need to make more efforts in the program. When a language has built-in OO features, OO programming development will be more convenient and efficient. On the other hand, an object-oriented language does not necessarily force you to write OO programs. For example, C++ can be considered "better C"; while Java requires everything to be a class, and also stipulates that a source file corresponds to a class definition. However, in Python, neither classes nor OOP are necessary for everyday programming. Although it was designed from the beginning to be object-oriented and supports OOP structurally, Python does not limit or require you to write OO code in your application. OOP is a powerful tool, no matter you are preparing to enter, learn, transition, or turn to OOP, you can do everything at your disposal. One of the most important reasons to consider working with OOD is that it directly provides a way to model and solve real-world problems and situations.

So far, this article on what is object-oriented in python is introduced. For more related what is object-oriented content in python, please search for ZaLou.Cn's previous articles or continue to browse related articles below. Hope you will support ZaLou more in the future. .Cn!

Recommended Posts

What is object-oriented in python
What is introspection in python
What is list comprehension in python
What is an anonymous function in Python
What is a sequence table in Python
What is the function of adb in python
What is Python variable scope
Is there function overloading in python
What does rc1 mean in python
What does def in python do
What is the use of Python
​What are the numbers in Python?
Everything in Python is an object
What does np do in python
Is there an algorithm in python language
Python 3.9 is here!
Functions in python
What is the scope of python variables
What is the id function of python
Python object-oriented example
Learn Python in one minute | Object-oriented (Chinese)
What are web development frameworks in python
What system is good for self-study python
Is a number in python a variable type
What is the function body of python
Python is mainly used in which directions
Python object-oriented basics
Is there a helper function in python
What is the difference between python and pycharm
Why python is popular
Python is short-crawling music
03. Operators in Python entry
Python is slowly fading
Python object-oriented magic method
What can Python do
Join function in Python
12. Network Programming in Python3
Concurrent requests in Python
Install python in Ubuntu
Context management in Python
Arithmetic operators in python
Write gui in python
MongoDB usage in Python
Str string in Python
Computational Geometry in Python
What is the difference between synchronous and asynchronous Python?
What is the advantage of python over corporate language
What are the ways to open files in python
What are python class attributes
Subscripts of tuples in Python
Is python an interpreted language?
Talking about inheritance in Python
Is python an interpreted language
What can python crawlers crawl
Noteworthy update points in Python 3.9
Python is short-world epidemic map
What databases can python use
Analysis of Python object-oriented programming
Containerize Python applications in 3 minutes
What can python collections do
Generators and iterators in Python