Python (Scripting) - Index numbers using enumerate
by
Jeremy Canfield |
Updated: November 14 2023
| Python (Scripting) articles
enumerate can be used to get the index number of an element. For example.
#!/usr/bin/python3
fruits = ["apple", "banana", "orange", "grapes"]
for index, item in enumerate(fruits):
print(f"index {index} = {item}")
Should return the following.
index 0 = apple
index 1 = banana
index 2 = orange
index 3 = grapes
Did you find this article helpful?
If so, consider buying me a coffee over at