The enumerate () function iterates over an index of a data object that can be traversed (such as a list, tuple, or string) and its corresponding elements, typically used in a for loop.
Enumerate (sequence, [start=0])
Sequence represents a sequence, iterator, or other supporting iteration object; Start represents the starting position of the index. Note that the start index has a starting position unrelated to sequence. The function return value is a enumerate object, such as an index value or its element, or both.
Example:
#-*-coding:utf-8-*-ImportOs,sysa='OSTBDN'Print(List (enumerate (a)))Print(Dict (Enumerate (a,start=1)))Print(Dict (Enumerate (a,start=8)) b=[0.33,9.02,8.88,2.61,999]Print(Tuple (Enumerate (b,2))) forIdx,valinchEnumerate (b):Print(B[idx]) forIdx,valinchEnumerate (a):Print(Idx,val)
Output:
Usage of enumerate () in Python