Iterate over lists in Python

Iterate over a list

>>> myList=[10,20,30,40,50]
>>> for value in myList:
...     print (value)
... 
10
20
30
40
50

Iterate over a list with indexes

>>> myList=[10,20,30,40,50]
>>> for index, value in enumerate(myList):
...     print (index, value)
... 
0 10
1 20
2 30
3 40
4 50

See also


Last update : 06/11/2018