Hello all I am currently learning python as my first programming language. I am on lesson More with ‘for’ and saw in the example the following code…
animals = [“cat”, “ant”, “bat”]
for animal in animals:
What I am having trouble understanding is how it is able to recognize the ‘animal’ part of the for loop, when the variable has not been defined. At first I thought perhaps it just recognizes this as the singular form of animals, but I doubt that makes sense. Am I to understand that the variable animal is being assigned to each of the animals in the list automatically and that the “for animal in animals” loop would work just as well if I were to change the code to be “for blahblahblah in animals” print blahblahblah?
(I did try this and it seemed to confirm my theory but thought I’d ask regardless in case I am missing something)