1 lists (list)
The following code assigns a variable to a list
a=['laay','aay','ay',' y']
There are indexes in the list that can be indexed to access the values in the list, or you can complete the slices by indexing
Print (a[0]) Print (a[1]) Print (a[-1]) Print (A[:3]) Print (A[:-1])
The printing results were
laayaayy['laay'aay'ay' ['laay'aay ' ay ']
Add elements, delete elements, change elements, find elements
A.append ('abc')# add ' abc ' to the last del# of the list Delete element of current index 1 in list a[1]='dd'# Change the list of elements indexed to 1 to ' DD 'print (A[0])# Prints an element with a list index of 0
List of loops
for inch A: Print (i)
Other functions of the list
CMP (List1, List2)# compares the elements of the two list to the number of Len (list)# elements and, if the list is empty, can be judged as Faslemax (list)# Returns the list element maximum min (list)# returns the list element minimum value list (seq)# convert tuples to lists
Other ways to List
List.count (obj)# count the number of occurrences of an element in a list list.extend (seq)# Append multiple values from another sequence at the end of the list (with a new list)List.index (obj)# Find the index position of the first occurrence of a value from the list List.insert (index, obj)# Inserts an object into the list List.pop (obj=list[-1])# removes an element from the list (the last element by default) and returns the value of the element List.remove (obj)# Removes the first occurrence of a value in the list list.reverse ()# Reverses the element in the list list.sort ([ Func])# sort the original list
Lists can be nested in lists, and lists in lists use logic consistent with general lists
a= [['laay','laa'],'aa',' ay']print(a[0][0])# remove ' laay 'print (a[0][1])# take out ' Laa '
2 tuples (tuple)
Tuples are almost identical to list usages, except that the elements in a tuple cannot be modified, but the tuple itself can be deleted!
A= ('laay','aay','ay',' y')
Python Learning sharing-list meta-groups