An OOP
Like C + + and Java, Python also has an OOP design.
Program: From the front to the back, a line, the machine can accept the order of the way, the way is probably "what you should do first, what the second should do, the advanced point of doing something if you encounter what to do, or how many times a thing to do, ..."
OOP: Abstract and understand the world from the "Class and object" way. For example, the object (object) may be divided into "biological" and "non-biological", "biological" can be divided into "human, animal, plant" and so on, "man" is divided into "men, women" and so on ... Nature is on the top of the world and is constantly being sorted. Similar to "genealogy", Can "inherit" between up and down.
Classes and objects. Classes are abstract, a group of overviews, objects are concrete, independent, such as I exist an independent person. Objects have properties and methods for their classes, as well as properties (methods) that belong to their own objects.
In the real world, classes have attributes (attribute) and behaviors (action); In abstract data, classes have data and methods. Between classes, there is inheritance (inheritance) and refinement, between classes and objects, and there is an instantiation. After instantiation, an object can increase its own data members outside of the inherited class members.
Two Python OOP
The pit in the end Python
Python is very powerful, there are many pits, one by one fill it.
A Python processing Chinese and encoding method
Before Python3.0, it was very painful to deal with Chinese inclusions because of coding. To make it completely not a problem, first, to understand the conversion between coding methods; second, a few practical examples in the hand.
Two Python basic syntax
1. Shallow copy assignment, transfer value and address call
Let's take a look at two examples of different operations when a function parameter is an int and a list of two types, to add a value of + + as an example.
# Pass-through value parameter
A = 1
def Change_integer (a):
A = a + 1
return A
# address addresses parameter
b = [[+]
def Change_list (b):
B[0] = b[0] + 1
return b
Print Change_integer (a)
Print ' A = ', a
print change_list (b)
Print ' b[0] = ', b[0]
#Result:
>a = 1
>b[0] = 2
In the first integer example, a variable of type int is passed to the function, and the original integer variable a does not change.
In the second list example, a list type variable is passed to the function, and the original LISTB changes.
The reason for this is that for a basic data type (for example, int), the function copies a new variable in memory, thus not affecting the original variable, which is called "value passing";
For list, which is not a basic variable, the function passes a pointer to the address of the sequence in memory, thus affecting the original value, called pointer passing.
Similarly, for the matrix or array type of data, also belongs to the non-basic type, so array_a = array_b such behavior, array_b do the same thing will affect the array_a, special attention!!
Python Object-oriented OOP