Description
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.
Grammar
The following is the syntax for the Enumerate () method:
Enumerate (sequence, [start=0])
Parameters
- Sequence--a sequence, iterator, or other supporting iteration object.
- Start-the subscript start position.
return value
Returns the enumerate (enum) object.
>>>seasons = ['Spring','Summer','Fall','Winter']>>>List (Enumerate (seasons)) [(0,'Spring'), (1,'Summer'), (2,'Fall'), (3,'Winter')]>>> List (Enumerate (seasons, start=1))#Small label starting from 1[(1,'Spring'), (2,'Summer'), (3,'Fall'), (4,'Winter')]
For Loop use enumerate
>>>seq = ['one', 'three' ] for in enumerate (seq): ... print (I,J) ... 0One 1 2 three>>>
Enumerate () function