name=['Liutao','Chuyunfei','Qifei','Xianmoumou']#Define a list#AddName.append ('123')#appends an element at the end of the list with only one additionalName.insert (1,'Liutao2')#you can add elements anywhere in the list, but the previous one is the index value, the index starts at 0, followed by the added content, and cannot be inserted in bulk#Modifyname[2]='Chenyifa' #to modify an element in a list by index subscript#DeleteName.remove ('Chenyifa')delName[2]name.pop ()#deletes the last element of the list by default, and also adds an index value#FindPrint(Name.index ('Liutao'))#Find element Index value#Extendedname2=['Liufeier',' the','Xianmoumou']#to expand a list by listName.extend (name2)#This must be done first extend, directly change the contents of the list itself, directly with print (Name.extend (name2)) will be displayed as nonePrint(name)#to calculate duplicate elements in a listPrint(Name.count ('Xianmoumou'))#Clear Listname.clear ()#Reverse ListName.reverse ()#and extend .#SortName.sort ()#sort order for special characters > Numbers > Uppercase letters > Lowercase letters ASCII sortPrint(name)#Print the entire listPrint(Name[0])#print an element with an index of 0 in the listPrint(Name[1:4])#Print the elements of the list index number 1 to 4
Note:
The reverse function, for the operation of the list, the result is to directly change the list itself (in order to save space), so the original list is changed directly to the result of the reversed you want, and the return value, is empty, does not return any value. Some other functions do the same
Python list (Day 1)