1. List slices
1l=['a','b','C','D','e','F']2 Print(L[1:5])#Slice according to the index number, but Gu Tou regardless of the tail3['b','C','D','e']4 Print(L[1:5:2])#according to the index number to slice, Gu Tou regardless of the tail, after adding a Haxi value every two empty one5['b','D']6 Print(L[2:5] )7['C','D','e']8 Print(L[-1])#-1 delegates from the back forward-1 for the last9 FTen One Al=['a','b','C','D','e','F'] - Print(L[-4:-1])#take it from the back -['C','D','e'] the Print(L[2:5])# -['C','D','e'] - Print(l[-1]) - F + Print([l[-4:]])#-4 from the back to the bottom 4 -[['C','D','e','F']]
2, append #追加
1 hobbies=['play','eat','sleep ','study']2 hobbies.append (' Girls')3print(hobbies)
3. Pop Delete
1 Delete by index number2 is not a simple delete, is to delete and return the deleted element, we can use a variable name to receive the return value3hobbies=['Play','Eat','Sleep','study']4X=hobbies.pop (1)5 Print(Hobbies)6['Play','Sleep','study']7 Print(x)8Eat
4. #队列: FIFO
1 Queue2Queue_l.append (' First')3Queue_l.append ('Second')4Queue_l.append ('Third')5 Print(queue_l)6 out Team7 Print(Queue_l.pop (0))8 Print(Queue_l.pop (0))9 Print(Queue_l.pop (0))Ten Print(Queue_l.pop (0)) One Print(Queue_l.pop (0)) A Print(Queue_l.pop (0))
5, del, remove delete
1 del # Simple Delete 2 hobbies.remove ('eat'# Simple Delete, and is the specified element to remove
6. Len Length
determine the default first length of the list hobbies=['play','eat',' Sleep ','study']print(len (hobbies))
7. In contains
1 Determines if the sleep element exists with hobbies in the return true, return false 2 hobbies=[ " play ", " eat ", " Span style= "COLOR: #800000" >sleep ", study " ] 3 print ( " sleep " in hobbies) 4 True
8. Insert
Specify a sequence to add an element hobbies=['Play','Eat','Sleep','study','Eat','Eat']hobbies.insert (1,'Walk') Hobbies.insert (1,['Walkl','Walk2','Walk3'])Print(hobbies)
9. Count
find out if the element is in the list how many hobbies=['play', 'eat',' Sleep ','study','eat',' Eat']print(Hobbies.count ('eat'))
10, Extend
1 add elements to a list after the list element2hobbies=['Play','Eat','Sleep','study','Eat','Eat']3Hobbies.extend (['WALK1','Walk2','Walk3'])4 Print(Hobbies)5['Play','Eat','Sleep','study','Eat','Eat','WALK1','Walk2','Walk3']
11. Index
1 View the position of the element in the list returns a sequence with multiple identical elements returning only the front2hobbies=['Play','Eat','Sleep','study','Eat','Eat']3 Print(Hobbies.index ('Eat'))
12. Sort
Arrange l =[100,9,-2,11,32]l.sort ()print(l) fromsmall to largeorder L =[100,9,-2,11,32] L.sort (Reverse=True)print(l) [100, 32, 11, 9,-2]
A built-in approach to Python's full stack development from getting started to giving up lists