Sign up for Free !!
World's first open source developer community with
Ticketing System
How do I access the index in a for loop, such that the output will be like below...
for
OUTPUT:
item 1 = 8 item 2 = 23 item 3 = 45 item 4 = 12 item 5 = 78
I want this output by using for loop
The problem can be solved by using enumerate() function in the for loop
ints = [8, 23, 45, 12, 78] for idx, val in enumerate(ints): print("item",idx+1,"=", val)
then the output returned will be:
OUTPUT: item 1 = 8 item 2 = 23 item 3 = 45 item 4 = 12 item 5 = 78
Please Login/Register to write your answer !!!
The problem can be solved by using enumerate() function in the for loop
then the output returned will be: