Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Looping over index

planets = ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn']
for var in planets:
    print(var)

Output:

Mercury
Venus
Earth
Mars
Jupiter
Saturn
planets = ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn']
for ix in range(len(planets)):
    print(ix, planets[ix])

Output:

0 Mercury
1 Venus
2 Earth
3 Mars
4 Jupiter
5 Saturn