List definition: is made up of specific elements which can make anything
List names=[' Li nei ', ' Han Meimei ', ' Lily '
Access element: List name [ordinal] (sequence number starting from 0) Names[0], if the sequence number is -1,-2, it points to the last element and the second penultimate element.
Modifying list elements: names[0]= "Wang"
add element: Names.append (' Yang ') added to the end
Insert element: Names.insert (0, ' Liu ')
Delete element: (1) del names[0]0 represents its index
(2) names.pop (0) Delete the last value of the list (pop if you need to continue using it)
(3) names.remove ("Li nei") deletes elements based on values
Sort:
(1) sort () permanent sorting in alphabetical and numeric order
(2) sorted (names) retains its original order and is only temporarily present.
Invert: reverse () Reverses the order of the list
List length: Len (names)
For loop for name in names: takes an element from names, stored in the variable name range (1,5) produces 1~4
Generate a list of numbers: List (range (1,6,2)) 2 is the step size
Statistical calculation of the list: (1) min (names) min
(2) max (names)
(3) sum (names)
List resolution: Nums=[num for NUM in range (1,11)]
Slice: Names[0:2]
Tuples: are immutable during program operation
Sizes= (15,20)
Although you cannot modify the elements of a tuple, you can assign values to tuples. Sizes= (20,25)
Use of Python lists