Some commonly used built-in functions

1 enumerate()

the enumerate () function is used to traverse a data object (such as a list, string, or tuples) as a combination index sequence, while the data lists and data standard, which is generally used in a for loop.

The following is the syntax enumerate () method:

enumerate(sequence, [start=0])
  • sequence - a sequence, an iterator, or other objects to support iteration.
  • start - start index position.

Return enumerate (enumeration) objects.

List1 = [ " this " , " is " , " a " , " test " ]
 for index, Item in the enumerate (List1):
     Print (index, Item)
result:
This 0
1 is a
 2 a
 3 tests

List1 = [ " this " , " is " , " a " , " test " ]
 for index, Item in the enumerate (list1,5 ):
     Print (index, Item)
Results: # Returns the index value and the index count from zero by default, can be modified
5 This
 6 is
 7 a
 8 Test

 

Guess you like

Origin www.cnblogs.com/bchy/p/11717040.html