For loop with index python

Code examples

23
0

python3 iterate through indexes

items=['baseball','basketball','football']
for index, item in enumerate(items):
    print(index, item)
15
0

python access index in for loop

for index, item in enumerate(items):
    print(index, item)

#if you want to start from 1 instead of 0
for count, item in enumerate(items, start=1):
    print(count, item)
6
0

for loop with index python3

colors = ["red", "green", "blue", "purple"]

for i in range(len(colors)):
    print(colors[i])
6
0

python for with iterator index

for index, value in enumerate(iterator):
    print(index, value)
3
0

how to loop the length of an array pytoh

array = range(10)
for i in range(len(array)):
  print(array[i])
0
0

for loop with index python

presidents = ["Washington", "Adams", "Jefferson", "Madison", "Monroe", "Adams", "Jackson"]
for i in range(len(presidents)):
    print("President {}: {}".format(i + 1, presidents[i]))

In other languages

This page is in other languages

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................