Counting as you go


#1


https://www.codecademy.com/en/courses/python-beginner-en-cxMGf/2/2?curriculum_id=4f89dab3d788890003000096

This code works fine but I'm trying to understand "index" in the code below.

Is index pre defined? How does the interpreter know to print the index for each item in choices? In other words how does the interpreter know what we mean by "index"?

choices = ['pizza', 'pasta', 'salad', 'nachos']

print 'Your choices are:'
for index, item in enumerate(choices):
    print index + 1, item


#2

You're defining it in the loop.
Look up what enumerate does
https://docs.python.org/2/library/functions.html
(and/or read the instructions in the exercise)


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.