One, create a list
Use square brackets around the different data items separated by commas. As shown below:
>>> name_list = ["root""GM""HLR "]
Second, access the value in the list
Use the subscript index to access the values in the list, as with the index of the string, starting with the 0 list index. Lists can be intercepted, combined, and so on.
>>> name_list['root'gm ' HLR']
Iii. what you can do to see the list
>>>Help (name_list)>>>dir (name_list)['Append','Clear','Copy','Count','Extend','Index','Insert','Pop','Remove','Reverse','Sort']
Append"STRING"): Appends a new value to the end of the list Clear:copy:count ("STRING"): Counts the number of occurrences of a string or value in the list Extend:index ("STRING"): The position of the first occurrence of a value in the list insert (n,"STRING"): Inserts a new value to position N of the list pop (obj=list[-1]): Removes the value from a position in the list, defaults to the last value of remove ("STRING"): Removes the first occurrence of a value in the list
Reverse(): List element values in reverse order
Sort(): The values in the list are sorted by ASCII code
Iv. Append
# Original List>>>name_list['Root','GM','HLR']#Add a root value>>> Name_list.append ("Root")#New List>>>name_list['Root','GM','HLR','Root']
V. Count
# count the number of times the root user appears in the list >>> name_list.count ("root")2
#additional, how to remove the root value from the list (this list has 2 values of root)>>>name_list['Root','HLR','GM','Root']>>> forIinchRange (Name_list.count ("Root") :... name_list.remove ("Root")... >>>name_list['HLR','GM']
Vi. Index
# original list >>> name_list['root'gm' ' HLR ' ' Root ' ]# See where HLR users first appear in the list >>> name_list.index ("HLR " )2
Seven, insert
#Original list>>>name_list['Root','GM','HLR','Root']#Add a test user at position 2 of the list>>> Name_list.insert (2,"Test")#New List>>>name_list['Root','GM','Test','HLR','Root']
Eight, pop
#Original list>>>name_list['Root','GM','Test','HLR','Root']#remove a value with a list position of 2>>> Name_list.pop (2)'Test'#New List>>>name_list['Root','GM','HLR','Root']#Delete the last value of a list>>>Name_list.pop ()'Root'#New List>>>name_list['Root','GM','HLR']
Nine, remove
#Original list
>>>name_list['Root','GM','HLR']#Add a new GM user
>>> Name_list.append ("GM")#New List>>>name_list['Root','GM','HLR','GM']#Removal of the first GM user
>>> Name_list.remove ("GM")#New List>>>name_list['Root','HLR','GM']
Ten, reverse
#Original list>>>name_list['Root','HLR','GM']#reverse arranging elements in a list>>>Name_list.reverse ()#New List>>>name_list['GM','HLR','Root']
Xi. sort
#Original list>>>name_list['Root','HLR','GM']#sort the list>>>Name_list.sort ()#New List>>>name_list['GM','HLR','Root']
How Python operates the list-list