9. More with 'for' question about animal


In the example given by Codecademy in 9., how does the computer know what animal is?

animals = ["cat", "ant", "bat"]

for animal in animals:
print animal


This is a good question. The way for each loops work, you are initializing a variable when saying for animal in animal. You can do this with a string as well. The 'in' keyword lets it know that animal is each piece of the variable.


Oh my gosh thank you so much! I got the solution but was so confused how the computer just knew what an animal was by default. Thank you and have a good rest of your day/night!


No problem! I know getting introduced to things, it can be so confusing, especially understanding how it worked. I dreaded for loops when I was new to them, so I know it's hard to imagine sometimes. :slight_smile:

You as well. :slight_smile: