1List = [" First","Second","Third","Fourth","Fifth"]2 3List2 = [1,2,3,4,5,6,6,7,8,8]4 5 Print(List[2])#a third value6 7 Print(List[1:3])#slices8 9 Ten Print(List[-1])#take it backwards. One A Print(List[-3:-1])#The scope of the inverted "Gu Tou disregard the tail" so the last one can not come out - - Print(list[-3:])#omit to output the last one the - -List.append ("Sixth")#Append is a supplementary meaning. - + Print(list[:]) - +List.insert (2,"one_point_five")#Insert at a location, such as 2, position insertion A Print(list[:]) at -LIST[2] ="haha" #Change Value - - Print(list[:]) - -List.remove ("haha")#Delete a specific variable in Print(list[:]) - to delLIST[0]#Delete Delete variable by location + Print(list[:]) - the * Print(List.index ("Fifth"))#find the first occurrence of a variable $ Panax NotoginsengList.insert (1,"Fifth") -List.insert (1,"Fifth")#Insert the Print(list[:]) + A Print(List.count ("Fifth"))#Number of a repeating variable the +List.reverse ()#return the element order all - Print(list[:]) $ $List.extend (LIST2)#Add the List2 to the back of the list. - Print(list[:]) - Print(list2[:]) the - delList2#You can delete a list entirelyWuyi the Print(List[::2])#Interval One step - Wu forIinchList#the form of circular printing, do not need to write out each - Print(i)
The above is a common usage
2.list Copy-note the depth copy
1List = [" First","Second","Third","Fourth","Fifth",["Sixth_one","Sixth_two"]]2 3List1 = List.copy ()#the entire copy is a list, but only shallow copy, copy only the first layer of the list, if there is a sub-list, then only when it is copied to the sub-list of memory address4 5 Print(list[:])6 Print(list1[:])7 8LIST[5][1] ="6.1" #observe the properties of a shallow copy9 Ten Print(list[:]) One Print(list1[:]) A -List1[5][0] ="6.0" #because this is a direct change in the memory location of the sub-list - Print(list[:]) the Print(list1[:]) - - ImportCopy -List = [" First","Second","Third","Fourth","Fifth",["Sixth_one","Sixth_two"]] + -List2 = copy.deepcopy (list)#A complete and complete copy + A at Print(list[:]) - Print(list2[:]) - -LIST[5][1] ="6.1" #to observe the properties of a deep copy - - Print(list[:]) in Print(list2[:])
Python learning-the use and editing of lists