Use the enumerate()
function to access the index value while iterating:
python
items = ['a', 'b', 'c']
for index, value in enumerate(items):
print(index, value)
Output:
css
0 a
1 b
2 c
Here, index
holds the current index, and value
holds the corresponding item.