Why does it print the entire list each time my loop runs?

Question

Why does it print the entire list each time my loop runs?

Answer

If you print the name of your list each time, instead of printing the variable, called item in the example, then that’s why. Take a look at the code below:

animals = ["cat", "doge", "liger"]
for animal in animals:
  print animals

I’ve told it to print animals, rather than each individual animal, which I told it to store in the singular animal variable after the word for.

1 Like

the output will be:
[“cat”, “doge”, “liger”]
[“cat”, “doge”, “liger”]
[“cat”, “doge”, “liger”]

If you want to show your output just one time, try this: print animal