Continue list:
To delete an element:
Copy Code code as follows:
A =[1, 2, 3, 4]
A[2:3] = [] #[1, 2, 4]
Del a[2] #[1, 2]
Empty list
Copy Code code as follows:
List is used as a stack (back-first out):
Copy Code code as follows:
stack = [3, 4, 5]
Stack.append (6)
Stack.append (7)
Stack.pop () # 7
Stack.pop () # 6
Stack.pop () # 5
Index with negative numbers:
Copy Code code as follows:
"+" combination list:
Copy Code code as follows:
end = [' st ', ' nd '] + 5*[' th '] + [' XY '] # [' St ', ' nd ', ' th ', ' th ', ' th ', ' th ', ' ', ' ', ' th ', ' xy ']
To find out the number of an element in a list:
Copy Code code as follows:
Lst. (' Hello ') # the number of Hello
List sort:
Copy Code code as follows:
Sort ()
#对链表中的元素进行适当的排序.
Reverse ()
#倒排链表中的元素
Problem with function pointer:
Copy Code code as follows:
def F2 (A, l=[])
L.append (a)
Return L
Print (F2 (1)) # 1
Print (F2 (2)) # 1, 2 L in this function call is [1]
Print (F2 (3)) # 1, 2, 3
The parameters in the function are:
* Parameter name: An argument that represents any number
* *: Indicates dictionary parameter
Control statement:
IF:
Copy Code code as follows:
If x < 0:
x = 0
print ' Negative changed to zero '
elif x = = 0:
print ' Zero '
elif x = = 1:
print ' single '
Else
print ' More '
For:
Copy Code code as follows:
A = [' Cat ', ' window ', ' defenestrate ']
For X in a:
Print x, Len (x)
While:
Copy Code code as follows:
A, b = 0, 1
While B < 1000:
Print B,
A, B = B, a+b
#1 1 2 3 5 8 13 21 34 55 89 144 233 377 610-987
Pass: null Action statement
Copy Code code as follows:
Dictionary: Data structure of key-value pairs
Use list to construct dictionary:
Copy Code code as follows:
Items = [(' Name ', ' DC '], (' Age ', 78)]
D = dict (items) #{' age ': +, ' name ': ' DC '}
Interesting comparisons:
Copy Code code as follows:
x = [] #list
X[2] = ' foo ' #出错
x = {} #dictionary
X[2] = ' foo ' #正确
The content is quite miscellaneous, and learn what to write down. Full use of the work of leisure and spare time to complete, more substantial.