Why does my "for" loop accept an undefined variable?



I got this question right, but I'm wondering why when I put "for numbers in start_list", it accepts numbers even though I never really defined it.

I expected it to give me an error instead of letting me pass.

start_list = [5, 3, 1, 2, 4]
square_list = []

# Your code here!
for numbers in start_list:
    square_list.append(numbers ** 2)
print square_list


you define it here:

for numbers in start_list:

you define numbers at the for loop declaration. Now, the for in loop will take care of most of the work, at each run of the loop, the for in loop will updated the numbers variable with the next number in the list.


@stetim94 is correct

If you get into running through strings and such, you will see the same thing.