python enumerate function documentation code example
Example 1: enumerate python
for index,subj in enumerate(subjects):
print(index,subj)
0 Statistics
1 Artificial intelligence
2 Biology
3 Commerce
4 Science
5 Maths
Example 2: enumerate python
grocery = ['bread', 'milk', 'butter']
for item in enumerate(grocery):
print(item)
print('\n')
for count, item in enumerate(grocery):
print(count, item)
print('\n')
for count, item in enumerate(grocery, 100):
print(count, item)
OUTPUT:
(0, 'bread')
(1, 'milk')
(2, 'butter')
0 bread
1 milk
2 butter
100 bread
101 milk
102 butter