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


#1



https://www.codecademy.com/courses/python-beginner-en-pwmb1/1/6?curriculum_id=4f89dab3d788890003000096

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)
square_list.sort()
print square_list


#2

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.


#3

@stetim94 is correct

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