Suppose I have a list of numbers and I want to access every item with its index number while iterating using the for
loop. I want that each element of the list I access by using its index number. Index number I got with the help of the for
loop with range
function but how do I use it, I don’t know. Let’s see the example given below:
Sample Code:
My_list = [ 234, 657, 918, 201, 394, 782 ]
for i in range(len(My_list):
# code that helps me access the items of the list
Output:
234
657
918
201
394
782
Can someone help me how do I access my list elements by using their index number? If you know any other alternative method that uses the for
loop for iterating the list and index number, share it with me.