Increase
By deleting
- Pop () #可以删除指定位置如果不给参数默认删除最后一个
- Remove () #可以删除指定的一个值
- Del
List1 = ["Jankinyu", "Kuankuan", "Comb", "card Farmer"]
Print (List1)
List1.remove ("Comb")Print(List1) list1.pop ()Print(List1)delList1[1]Print(List1)#Output results
#[' Jankinyu ', ' Kuankuan ', ' comb ', ' chi Nong ']
#[' Jankinyu ', ' Kuankuan ', ' Chi Nong ']#[' Jankinyu ', ' Kuankuan ']#[' Jankinyu ']
Change
- List[index]=value
LIST3 = ['1','2','3','4','5','6','7','8','9']list3[8] = 666Print(LIST3)#Output Results#[' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ', ' 7 ', ' 8 ', 666]
Check
- Index () #查找值的下标
- Slice List[start:end:step]
LIST3 = ['1','2','3','4','5','6','7','8','9']Print(List3[0:9:2])Print("take the value of subscript 0-4 in the LIST3:", List3[0:5])Print(LIST3)#Output Results#[' 1 ', ' 3 ', ' 5 ', ' 7 ', ' 9 ']#take the value of subscript 0-4 in list3: [' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ']#8
Copy
-
- Alias bindings: List1=list2
- A shallow copy of 4 ways
- Names1 = Names.copy () # Shallow copy equivalent to Copy.copy ()
- Names2 = copy.copy (names)
- Names3 = names[:]
- NAMES4 = list (names)
Deep copy: List2=copy.deepcopy (List1)
1 __author__="Kuankuan"2 ImportCopy3list_name=[1,2,3,4,5]4Name=list_name.copy ()5 Print(name)6name1=copy.copy (list_name)7 Print(name1)8Name2=list_name[:]9 Print(name2)Tenname3=list (list_name) One Print(List_name) Ab=copy.deepcopy (list_name) - Print(b)
Other
-
- Count: Count ()
- Invert: Reverse ()
- Sort: Sort () # Follow the rules of the ASCII code table
- Extension: Extend ()
- Traverse: for...in ...
- Empty: Clear ()
A common approach to Python learning path-list