Object-oriented programming of Python advanced features (classes and objects)
First, Class and object:
Process-oriented and object-oriented programming
Process-oriented programming: Functional programming, C-programs, etc.
Object-Oriented Programming: C++,java,python, etc.
Classes and objects: Two important concepts in object-oriented
Class: Is the abstraction of things, such as: Car models
Object: Is an instance of a class, for example: QQ sedan, bus
Example Description:
A car model can abstract the characteristics and behavior of a car, and then it can be used as an instance of a real car entity.
Second, the Python class definition
Definition of Python class:
Use the class keyword to define a class and capitalize the first letter of the class name;
When a programmer needs to create a type that cannot be represented by a simple type, it needs to create a class;
Classes combine important variables and functions, which are also known as "encapsulation";
The structure of the Python class:
>>>class class Name:
... Member variables
... member functions
The creation of the class:
Class MyClass ():
def fun: # There is at least one parameter in the method of the # class self
print "Hello world!"
>>> class Test:
... first = 123
... second = 456
... def f (self):
... return ' test '
...
>>> Milo = Test ()
>>> Loyu = Test ()
>>> Loyu.first
123
>>> LOYU.F ()
' Test '
Object is created:
The process of creating an object is called instantiation;
When an object is created, it contains three aspects of the attribute: the handle, property, and method of the object
Handles are used to distinguish between different objects
The properties and methods of an object correspond to member variables and member functions in a class
This article is from "Meteor Yu" blog, please be sure to keep this source http://8789878.blog.51cto.com/8779878/1832929
13. Object-oriented programming of Python advanced functions