Counting as you go


#1



`python

choices = ['pizza', 'pasta', 'salad', 'nachos']
print 'Your choices are:'
for index, item in enumerate(choices):
print index+1, item.

I am not able to understand the syntax of for loop in the code given below.
Please tell me how and which value is assign in "index" and "item" after every cycle of the loop.


#2

enumerate() is a built in function which returns two things: the index of the item in the list, and the item in the list. enumerate will assign the index to the first variable in the loop (index) and the item to the second variable (item) in the loop

so python assigns the index and item to the variable you use in the loop


#3

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