The enumerate Function in Python


Use enumerate to get both the index and the value of items in a list during a loop.

Source Code

fruits = ["apple", "banana", "cherry"]
for index, fruit in enumerate(fruits):
    print(index, fruit)
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments