List of lists:
1 #Li = [one, one, one, one, and one]2 #Parameters3 #1. The original value was last appended4 #object. Method (..) # Li Object calls the Append method5 #li.append (5)6 #Li.append ("Alex")7 #li.append ([1234,2323])8 #Print (LI)9 #2 emptying the listTen #li.clear () One #Print (LI) A - #3 Copy, shallow copy - #v = li.copy () the #Print (v) - #4. Count the number of occurrences of an element - #v = li.count (a) - #Print (v) + - ## 5. Expansion of the original list, parameters: can iterate objects + #Li = [one, one, one, one, and one] A #Li.append ([9898, "incredibly"]) at #Print (LI) - #[11, 22, 33, 22, 44, [9898, ' incredibly '] - - #Li.extend ([9898, "incredibly"]) - #for i in [9898, "amazing"]: - #li.append (i) in #[11, 22, 33, 22, 44, 9898, ' incredibly '] - # to #li.extend ("incredibly") + #Print (LI) - the #6. Get the current value index position by value (left priority) * #Li = [one, one, one, one, and one] $ #v= Li.index ($)Panax Notoginseng #Print (v) - the #7. Inserting an element at the specified index location + #Li = [one, one, one, one, and one] A #Li.insert (0,99) the #Print (LI) + - #8. Delete a value (1. Specify an index; 2. The last one by default) and get the deleted value $ #Li = [one, one, one, one, and one] $ #v = li.pop () - #Print (LI) - #Print (v) the - #Li = [one, one, one, one, and one]Wuyi #v = li.pop (1) the #Print (LI) - #Print (v) Wu #9. Delete the specified value from the list, the left priority - #Li = [one, one, one, one, and one] About #Li.remove (+) $ #Print (LI) - #ps:pop remove del li[0] del Li[7:9] Clear - - #10 Flipping the current list A #Li = [one, one, one, one, and one] + #Li.reverse () the #Print (LI) - $ #11 Sorting of lists theLi = [11, 44, 22, 33, 22] the Li.sort () the #Li.sort (reverse=true) the Print(LI)
View Code
Related actions:
1 #Modify2 #li[1] =3 #Print (LI)4 #li[1] = [11,22,33,44]5 #Print (LI)6 7 #Delete, the first way8 #del Li[1]9 #Print (LI)Ten ############## 7 slices One #Modify A #Li[1:3] = [120,90] - #Print (LI) - #Delete the #del Li[2:6] - #Print (LI) - - #8 in Operation + #Li = [1, p, 9, "age", ["Shi Zhenwen", ["19", 10], "Pommeron"], "Alex", True] - #v1 = "Shi Zhenwen" in Li + #Print (v1) A #v2 = ' age ' in Li at #Print (v2) - ###### The elements in the list, - - #9 Operation - #Li = [1, p, 9, "age", ["Shi Zhenwen", ["19", 10], "Pommeron"], "Alex", True] - #print (li[4][1][0]) in #Li[4][1][0] - #[1] to + #Li = [1, p, 9, "age", ["Shi Zhenwen", ["19", 10], "Pommeron"], "Alex", True] - the #s = "POUASKDFAUSPDFIAJSDKFJ" * #s = 123 $ #a = "123"Panax Notoginseng #Int (a) - #A = 123 the #Str (a) + #10 Conversion A #string Transform list li = List ("ASDFASDFASDF"), internal use for loop the #s = "POUASKDFAUSPDFIAJSDKFJ" + #New_li = List (s) - #print (New_li) $ $ #the list is converted into a string, - #You need to write your for loop one by one: both numbers and strings - #Li = [11,22,33, "123", "Alex"] the #r = str (LI) # ' [11,22,33, ' 123 ', ' Alex '] ' - #print (R)Wuyi #s = "" the #For I in Li: - #s = s + str (i) Wu #print (s) - #directly using the string join method: The elements in the list are only strings About #li = ["123", "Alex"] $ #v = "". Join (LI) - #Print (v) - - ## # Add: cannot be modified after a string is created A #v = "Alex" + #v = v.replace (' l ', ' el ') the #Print (v) - $ #li = [11,22,33,44] the #Li[0] the #li[0] = 999 the the #s = "Alex" - #Li[0] in #s[0] = "E" the the #li = [11,22,33,44] About #Print (LI) the #Print (LI) the #Print (LI) the #Print (LI) + #Print (LI) - #Print (LI) the #Print (LI)Bayi #Print (LI) the #list, ordered, elements can be modified the - #List - #List the #li = [111,22,33,44]
View Code
List of Python