There are several ways to sequence: List.append (obj)---------add elements to the end of the series
List.insert (index,obj)---------inserting elements according to index subscript
List.pop (Index)------------the subscript element corresponding to index is deleted and the last element is deleted by default
List.count (obj)------------statistics on the number of OBJ elements
List.remove (obj)----------Delete duplicate and preceding elements
List.severse ()----------elements in the inverse sequence
List.sort ()----------sequence element ordering
List.index (obj)--------See what the subscript for this element is
List2.exten (list1)-------add elements from the list1 sequence at the end of the list2 sequence
Example:
1) list.append (obj)
List1 = [1,2,3,4, ' China ', ' Us ']list1.append (5) print (List1) # Runtime output [1,2,3,4, ' China ', ' US ', 5]
2) List.insert (2, ' Canada ')
List2 = [1,2,3,4.0, ' China ', ' Us ']list2.insert (2, ' Canada ') print (LIST2)
# run-Time output results
[1, 2, ' Canada ', 3, 4, ' China ', ' USA ']
3) List.pop ()
List3 = [1, 2, ' Canada ', 3, 4, ' China ', ' Us ']print (List3.pop ()) #输出结果 [1, 2, ' Canada ', 3, 4, ' China ']
Print (List3.pop (-1))
#输出结果
[1, 2, ' Canada ', 3, 4, ' China ']
Print (List3.pop (3))
#输出结果
[1,2,3,4, ' China ', ' America ']
4) List.count (JBO)
List4 = [1,2,3,3,4, ' China ', 3]list4.count (3) #输出结果3
5) list.remove (obj)
LIST5 = [1, 2, ' Canada ', 3, 4, ' China ', ' USA ']
List5.remove (' America ')
Print (LIST5) # output results [1, 2, ' Canada ', 3, 4, ' China ']
6) List.severse ()
List7 = [1,3,4,2, ' a ', ' R ', ' H ']list6.reverse () print (LIST6) #输出结果
[' H ', ' R ', ' A ', 2, 4, 3, 1]
7) List.sort ()
LIST7 = [2,4,6,3,5,1]list7.sort () print (LIST7) #输出结果 [1, 2, 3, 4, 5, 6]
8) List.index (obj)
List8 = [' A ', ' B ', ' C ', ' d ', 1, 2, 3, 4, 5, 6]list8.index (' B ') # output result 1
9) List2.exten (List1)
A = [1, 2, 3, 4, 5, 6]b = [' A ', ' B ', ' C ', ' d ']b.extend (a) print (b) # output results [' A ', ' B ', ' C ', ' d ', 1, 2, 3, 4, 5, 6]
Summary: Some methods of the series