1) variable does not need to be deleted, can be recycled directly using
>>>a = 10>>>print A.type (a) 10,<type ' int ' >>>>a = 1.3>>>print a.type (a) 10, <type ' float ' >
2) Sequence: a set of sequential elements
Tuple: meta-ancestor, once the element is determined, it cannot be changed list: lists, elements and can be arbitrarily modified s[1]=3, the list is assigned, but the tuple is not allowed to do so str: string is a kind of ancestor
2.1) Index: [ upper limit: Lower limit: Step ] does not contain upper limit
>>>print S[:5] from start to subscript 4, excluding 5 >>>print s[2:] Starting from 2 to the last >>>print S[0:5:2] starting from 0 to subscript 4, excluding 5, removing 0, 2, 4 >>>print s[2,0,-1] from subscript 2 to 1, excluding 0 >>>print s[-1] last element >>>print s[-3] Last third element
3) Loop: For Loop, while loop
Continue: Skips a loop for I in range: if i = = 2:continue print I >>> when i==2 is not executed, so the output 0,1,3,4,5,6,7,8,9 break: Jump out of the entire loop for I in range: if i = = 2:break Print I >>> When i==2, jump out of the loop, so the output 0,1
4) function
convenient for us to repeat the use of a certain function;
Return is used to return a value, the function body will end when the return is encountered, and if there is no return, Python will throw none, indicating no value
4.1) parameter passing of the function:
The value of the function parameter of Python, which is the values of the memory address that the variable points to;
Classification: Non-changeable object parameters, variable object transfer
4.2) Python Variables and objects
The variable is of no type and can point to any object;
Objects: Divided into immutable objects (int/tuple/string, etc.) and mutable objects (list/dict, etc.)
A = 1 def change_integer (a): a = a + 1 return a print Change_integer (a) print a>>> output 2 1 Immutable object parameters: A variable of the base data type, When a variable is passed to a function, the function copies a new variable in memory, without affecting the original variable b = [1] def change_list (b): b[0] = b[0] + return b print change_list (b) PR int b >>> output [2,2,3] [2,2,3] Variable object argument; table, the table is passed to the function is a pointer, the pointer to the position of the sequence in memory, the function of the table operation will be in the original memory, thereby affecting the original variable
This article from "Kong Love to Eat fish" blog, declined reprint!
"Python" starts with Python and learns to program