Python Enumerate For
The enumerate function in Python is used to get the index of the items in an iterable. The Python Enumerate for, adds a counter to the for loop as show in the example below.
-----------------------------------------------------
#Output
0 Monday
1 Tuesday
2 Wednesday
3 Thursday
4 Friday
#Python enumerate for days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"] for index, day in enumerate(days): print(index, day)
-----------------------------------------------------
#Output
0 Monday
1 Tuesday
2 Wednesday
3 Thursday
4 Friday
Comments
Post a Comment