If we want to print all values from a list one after the other, we can do the following:
This method is not efficient as the same code is repeated for every element in the list.
Instead we can use a for loop to do the same in a much more efficient way.
Here animal
is the iterator variable in this code. It temporarily holds each value from the list animals
as the for
loop iterates over it. During each iteration, the loop assigns the next value from the list to the animal
variable, allowing you to work with that specific element within the loop.