How to Use Enumerate to Get Index and Value in Python

fruits = ["apple", "banana", "orange"]
for index, value in enumerate(fruits):
    print(f"Index: {index}, Value: {value}")

Output:

Index: 0, Value: apple
Index: 1, Value: banana
Index: 2, Value: orange

Leave a Comment

Your email address will not be published.