First, a list of
1.1, the format of the list
Any type can be nested list, in parentheses, "" dividing each element in the list of elements can be numbers, strings, lists, Boolean can go into all ..
li = [1, 12, 9, "age", ["aaa", ["19", 10], "bbb"], "ccc", False]
= [11, 22, 33, 22, 44]
1.2, the list of methods
. 1) the append () ==> added to the end of the original value, the parameter must iterables
li = [1, 2, 3, 4] li.append(5) li.append("abc") li.append([1234, 2323]) print(li) #[1, 2, 3, 4, 5, 'abc', [1234, 2323]]
2) the Clear () ==> Clear List
li = [1, 2, 3, 4] li.clear () print (li) # []
. 3) Copy () ==> shallow copy
li = [1, 2, 3, 4] v = li.copy () print (v) # [1, 2, 3, 4]
. 4) COUNT () number ==> element appears calculated
li = [1, 2, 3, 4, 1] v = li.count (1) print (v) # 2
5) Extend () ==> extended the original list of parameters: iterables
# Using the append Li = [. 11, 22 is, 33 is, 22 is, 44 is] li.append ([ "AA", "BB"]) Print (Li) # [. 11, 22 is, 33 is, 22 is, 44 is, [ 'AA' , 'bb']] # nested list # using Extend Li = [. 11, 22 is, 33 is, 22 is, 44 is] li.extend ([55, "AA"]) # [. 11, 22 is, 33 is, 22 is, 44 is, 55, 'aa'] # a list of print (li)
. 6) index () ==> value obtained in accordance with the current value of the index position (left priority)
li = [11, 22, 33, 22, 44] v = li.index (22) print (v) # 1
. 7) INSERT () ==> insertion element at the specified index
= [11, 22, 33, 22, 44] li.insert (0,99) print () # [99, 11, 22, 33, 22, 44]
8) POP () ==> Delete a value (1. Specify the index; 2 default last), and get the value of the deleted
li = [11, 22, 33, 22, 44] v = li.pop () print (li) # [11, 22, 33, 22] print (v) # 44 li = [11, 22, 33, 22 44] v = li.pop (1) print (li) # [11, 33, 22, 44] print (v) # 22
9) the Remove) ( ==> delete the specified value list, left priority
= Li [. 11, 22 is, 33 is, 22 is, 44 is] li.remove (22 is) Print (Li) # [. 11, 33 is, 22 is, 44 is] # delete list Method: #pop Remove del Li [0] del Li [. 7 : 9] clear
10) the Sort () Sort ==> list
it = [11.44, 22, 33, 22] li.sort () # [11, 22, 22, 33, 44] li.sort (reverse = True) # [44, 33, 22, 22, 11] print (you)
1.3, the list of values
1) index value
li = [11.44, 22, 33, 22] print (li [3]) # 33
2) cut, sliced the result is a list of
li = [11.44, 22, 33, 22] print (li [2: -1]) # [22, 33]
3) while or for loop
for item in li: print(item)