A list of lists
1. Defining the list
a= ['a','b','c',' D ','e','f']
2. List Query
#access each element of the list with an index starting at 0#Output index = 1 valuePrint(a[1]) b#take the value from index 1 to the lastPrint(a[1:]) ['b','C','D','e','F']#Output last elementPrint(a[-1]) F#take forward from the penultimate valuePrint(a[:-1]) ['a','b','C','D','e']#from left to second value, take one of twoPrint(A[1:-1:2]) ['b','D']#from left to right, take one of two .Print(A[1::2]) ['b','D','F']
3. Add
# Append, default added to last a.append ('f') print(a)# Insert , the data can be inserted into any position A.insert (2,'g'print( A
4. Modifications
a[0]='hello'print(a) a[1:3]=['h',' m']print(a)
5. Delete
#RemoveA.remove (a[4]) Print(a)#Pop, the method can return the deleted valueb = A.pop (1) Print(a)Print(b)#deldelA[0]Print(a)#del Delete entire objectdela#clear clears the sequence, at which point an empty arrayA.clear ()
Python Basics list, tuple, dictionary