I have my code right, but have a question


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


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


OHHH okay, thanks! I get it now!


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