I have my code right, but have a question


#1

In this code, I had number instead of item and the code wouldn’t go through because I hadn’t defined what a number was. I get that. But why would the word ‘item’ work without defining it? Sorry if it’s a stupid question, just trying to learn! Thanks!


a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
for item in a:
    if item % 2 == 0:
        print item



#2

you did define item here:

for item in a:

the loop iterator gets declared inside the loop, python will assign each value of the list to item


#3

OHHH okay, thanks! I get it now!


#4

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