The enumerate() Function for Getting Index and Value in Python


Retrieve both the index and the value when looping over a sequence.

Source Code

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