Is number or animal already pre-defined in python?


#1

is number or animal already pre-defined in python?

In the example below, how did the for function know what is a animal?

animals = ["cat", "ant", "bat"]
animals.sort()

for animal in animals:
print animal


#2

The for loop doesn't know what an animal is. It's just using animal as a placeholder for each item in the list passed into it (animals).
You could replace animal with foo and the code would run the same. :smile:

animals = ["cat", "ant", "bat"]
animals.sort()

for foo in animals:
    print foo

Hope this helps!


#3

arhh...i get it now, foo/animal was just a variable that got assigned due to the "for" function. Thanks doublediamond Sir/M'am!


#4

No problem @methodrockstar85962 :smile: Could you press the button that says "solution" or "accept answer" to show that the question is answered? Thanks