Example 1: python for with iterator index
for index, value in enumerate(iterator):
print(index, value)
Example 2: enumerate in python
languages = ['Python', 'C', 'C++', 'C#', 'Java']
i = 0
for language in languages:
print(i, language)
i+=1
for i, language in enumerate(languages):
print(i, language)
Example 3: python enumerate for loop
presidents = ["Washington", "Adams", "Jefferson", "Madison", "Monroe", "Adams", "Jackson"]
for num, name in enumerate(presidents, start=1):
print("President {}: {}".format(num, name))
Example 4: how to use enumerate in python
rhymes=['check','make','rake']
for rhyme in enumerate(rhymes):
print(rhyme)
(0, 'check')
(1, 'make')
(2, 'rake')
Example 5: enumerate python
l1 = ['alu','noodles','vada-pav','bhindi']
for index, item in enumerate(l1):
if index %2 == 0:
print(f'jarvin get {item}')
Example 6: for loop with enumerate python
presidents = ["Washington", "Adams", "Jefferson"]
for num, name in enumerate(presidents, start=0):
print("President {}: {}".format(num, name))