Home > Article > Backend Development > Detailed explanation of examples of python classes
Programming is a process in which programmers use codes composed of specific syntax + data structures + algorithms to tell the computer how to perform tasks. A program is a program that programmers use to get a A set of instructions written based on the results of a task. As the saying goes, all roads lead to Rome. There are many different ways to implement a task. The categories of programming methods are summarized by summarizing the characteristics of these different programming methods, namely for the programming paradigm. Different programming paradigms essentially represent different problem-solving ideas for various types of tasks. Most languages only support one programming paradigm. Of course, some languages can support multiple programming paradigms at the same time. The two most important programming paradigms are procedural programming and object-oriented programming.
Object-oriented programming: OOP object oriented programming
Use 'classes' and 'objects' to create various models to describe the real world.
Several cores facing the opposite side:
Class class: A class is an abstraction, blueprint, and prototype of a class of objects with the same attributes. All these objects are defined in the class. Methods common to attributes (variables (data)).
Object object: An object is an instantiated instance of a class. A class must be instantiated before it can be called in a program. A class can Instantiate multiple objects, and each object can have different attributes.
ENCAPSULATION Encapsulation:
The assignment of data in the class and the internal call are transparent to external users, which makes The class becomes a container, which contains the data and methods of the class.
Inheritance:
A class can derive a subclass, and the attributes and methods defined in this parent class are automatically Inherited by subclasses.
Polymorphism Polymorphism:
Polymorphism is an important feature of object-oriented, one interface, multiple implementations, which means that different subclasses are derived from a base class, and Each subclass inherits the same method name and implements the method of the parent class differently!
1 def dog(name,gj):#定义dog 2 data={ 3 'name':name, 4 'gj':gj 5 6 } 7 return data 8 def pop(name,gj,lev,hp,mp):#定义人 9 data={10 'name':name,11 'gj':gj,12 'lev':hp,13 'hp':hp,14 'mp':mp15 }16 return data17 18 def bark(d):19 print("dog %s:汪汪"%d['name'])20 21 def walk(p):22 print('person %s:说话'%p['name'])23 24 dog1=dog('大黄','300')25 print(dog1)
The above is the detailed content of Detailed explanation of examples of python classes. For more information, please follow other related articles on the PHP Chinese website!