Face to face: (advanced)

Object-oriented is a programming method. The implementation of this programming method is based on the use of classes and objects. A


class is a template, and the template wraps multiple "functions" for use (you can say that the common variables in multiple functions are encapsulated into objects )


object, an instance (ie: an object) created from a template, the instance is used to call functions that are wrapped in a class


Object-oriented three characteristics: encapsulation, inheritance and polymorphism

1. Fields: ordinary fields belong to objects, and static fields belong to classes

2. Method:

Ordinary method: called by the object; at least one self parameter; when the ordinary method is executed, the object that calls the method is automatically assigned to self;



Class method: called by the class; at least one cls parameter; when the class method is executed, the class that calls the method is automatically copied to cls;


Static method: called by the class; no default parameters

3. Attributes: Two ways to define: 1. Decorator 2. Static fields

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325721525&siteId=291194637