Counting as you go


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


You're defining it in the loop.
Look up what enumerate does
(and/or read the instructions in the exercise)


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