For Loopยถ
Something is an iterable if you can iterate over it using a โfor loopโ. Strings and lists are both iterables.
Letโs make a for loop:
>>> fruits = ["strawberries", "bananas", "apples", "oranges"]
>>>
>>> for fruit in fruits:
... print(fruit)
...
strawberries
bananas
apples
oranges
Here, fruit
is a variable name which will contain a different item in each iteration of the loop.
We can use any name we like for this variable:
>>> for x in fruits:
... print(x)
...
strawberries
bananas
apples
oranges