Object-oriented Python
Object-oriented programming is a programmatic approach that needs to be implemented using classes and objects.
Therefore, object-oriented programming is actually the use of "class" and "object".
A class is a template that can contain multiple functions and functions in a template.
Objects are instances created from templates that can execute functions in a class through an instance object
- Class is a keyword that indicates that classes
- Create the object, and then add parentheses to the class name
PS: A function in a class The first argument must be self (see in detail: Encapsulation of the three main characteristics of a class)
A function defined in a class is called a "method"
#Create ClassclassFoo:defBar (self):Print 'Bar' defHello (self, name):Print 'I am%s'%name#Create object from class Foo objobj =Foo () obj. Bar ()#Execute Bar MethodObj. Hello ('Wupeiqi')#Execute the Hello method
Object-oriented three major features:
The three major characteristics of object-oriented are: encapsulation, inheritance and polymorphism.
First, the package
Encapsulation, as the name implies, encapsulates the content somewhere and then calls the content that is encapsulated somewhere.
Therefore, when using object-oriented encapsulation features, you need:
- Encapsulate content somewhere
- To invoke the encapsulated content from somewhere
First step: encapsulate the content somewhere
Object-oriented Python