To iterate over the indices of a sequence, combine range() and len() : List Loop « List « Python






To iterate over the indices of a sequence, combine range() and len()

To iterate over the indices of a sequence, combine range() and len()

a = ['Mary', 'had', 'a', 'little', 'lamb']

for i in range(len(a)):
     print i, a[i]

           
       








Related examples in the same category

1.List for iterationList for iteration
2.For StatementsFor Statements
3.Loop through a list: for inLoop through a list: for in
4.For loop demoFor loop demo
5.For loop for ListFor loop for List