Continue List:
Delete element:Copy codeThe Code is as follows: a = [1, 2, 3, 4]
A [2: 3] = [] # [1, 2, 4]
Del a [2] # [1, 2]
Clear listCopy codeThe Code is as follows: a [:] = []
Del a [:]
List is used as a stack (post-in-first-out ):Copy codeThe Code is as follows: stack = [3, 4, 5]
Stack. append (6)
Stack. append (7)
Stack. pop () #7
Stack. pop () #6
Stack. pop () #5
Index with negative number:Copy codeThe Code is as follows: B = [1, 2, 3, 4]
B [-2] #3
"+" Combination list:Copy codeThe Code is as follows: end = ['st', 'nd'] + 5 * ['th'] + ['xy'] # ['st', 'nd ', 'th', 'xy']
Find the number of elements in the list:Copy codeThe Code is as follows: lst. ('hello') # Number of hello'
List sorting:Copy codeThe Code is as follows: sort ()
# Sort the elements in the linked list.
Reverse ()
# Inverted list elements
Function pointer problems:Copy codeThe Code is as follows: def f2 (a, L = [])
L. append ()
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 include:
* Parameter Name: any number of parameters
**: Indicates the dictionary parameter.
Control statement:
IF:Copy codeThe Code is as follows: if x <0:
X = 0
Print 'negative changed to zero'
Elif x = 0:
Print 'zero'
Elif x = 1:
Print 'singles'
Else:
Print 'more'
FOR:Copy codeThe Code is as follows: a = ['cat', 'window', 'deletestrate']
For x in:
Print x, len (x)
WHILE:Copy codeThe Code is 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
Pass: NULL operation statementCopy codeThe Code is as follows: while True:
Pass
Dictionary: Data Structure of key-value pairs
Use list to construct a dictionary:Copy codeThe Code is as follows: items = [('name', 'dc'), ('age', 78)]
D = dict (items) # {'age': 78, 'name': 'dc '}
Interesting comparison:Copy codeThe Code is as follows: x = [] # list
X [2] = 'foo' # error
X ={}# dictionary
X [2] = 'foo' # correct
The content is complex. Remember what you learn. It makes full use of free time and spare time at work.