Bootstrap FreeKB - Python (Scripting) - Index numbers using enumerate
Python (Scripting) - Index numbers using enumerate

Updated:   |  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 Buy Me A Coffee



Comments


Add a Comment


Please enter 79f888 in the box below so that we can be sure you are a human.