Using enumerate() for Index-Value Pairs in Python


Use enumerate() when looping through a sequence and you need both the index and the value.

Source Code

for index, value in enumerate(["red", "green", "blue"]):
    print(f"{index}: {value}")
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments