Actions for Python list (add delete)
1. Additions to the list: Append and Extend
The difference between append and extend: Append can only append 1 elements, extend may append multiple
>>> lst1=[1,2,3,4]>>> lst1.append (5)>>> lst1[1, 2, 3, 4, 5] >>> lst1.extend ([6,7,8])>>> lst1[1, 2, 3, 4, 5, 6, 7, 8]
2. Deletion and substitution of lists
Delete Using Del and pop
Use subscript to replace
>>> lst2=['1','Google','2','IBM','3','Huawei','4','XJZX']>>> lst2[1]='Baidu'>>>lst2['1','Baidu','2','IBM','3','Huawei','4','XJZX']>>> Lst2.pop (1)'Baidu'>>>lst2['1','2','IBM','3','Huawei','4','XJZX']>>>delLst2[0]>>>lst2['2','IBM','3','Huawei','4','XJZX']
3. use the number of elements in the "Len (name)" Statistics list
>>> Len (LST2)
6
Two.
The difference between a list and a tuple
1. The same point:
Tuples and lists store the container for the elements, and the subscripts are all starting at 0, separated by commas
2 different points
The list can be modified to change the data type, when defined as []
Tuples cannot be modified to be defined as ()
Python list action (add delete) list and tuple differences