The enumerate () function is used to combine a data object that can be traversed (such as a list, tuple, or string) into an index sequence, while listing data and data subscripts, typically used in a for loop.
In plain English, it is to give a group of elements, for example, we are in the collation of Excel table, the habit in the first field with an ordinal field, write on the 1,2,3,4,5 ... the same reason.
Grammar
The following is the syntax for the Enumerate () method:
Enumerate(sequence,[start=0])
Instance
The following shows an example of using the Enumerate () method:
>>>seasons = [ ' spring Span class= "Hl-code", "summer fall "winter >>> list(enumerate(seasons)) [(0 "spring (1 "summer (2 "fall (3 "winter < Span class= "hl-quotes" > < Span class= "hl-brackets" > >>> List (enumerate ( seasonsstart =1) # Small Mark starting from 1 [(1 "spring (2 "summer (3 "fall (4 "winter With A For loop
For loop use enumerate
Python Enumerate () function