Defining variables in 'for' loops


The very first exercise of this section, "BeFOR We Begin," has you create this code:

names = ["Adam","Alex","Mariah","Martine","Columbus"]
for name in names:
    print name

My question is: in an actual program, would you need to define the variable "name" somewhere before this? Otherwise, how does Python recognize that "name" is referring to the list items?


In this situation 'name' is just a place holder. Do this:

Replace 'name' with 'biscuit' in both places where 'name' appears in your code and see what happens.


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