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

Enumerate returns tuples

  • enumerate
  • tuple
planets = ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn']

enu = enumerate(planets)
print(type(enu).__name__)
print(enu)
#for t in enu:
#    print(t)
for ix, planet in enu:
    print(ix, planet)

#print('-----')
#
#element = next(enu)
#print(type(element))
#print(element)
#
#print('-----')
#
#for tpl in enumerate(planets):
#    print(tpl[0], tpl[1])
#

Output:

enumerate
<enumerate object at 0x7f7ede7e37c0>
-----
<class 'tuple'>
(0, 'Mercury')
-----
0 Mercury
1 Venus
2 Earth
3 Mars
4 Jupiter
5 Saturn