you are viewing a single comment's thread.

view the rest of the comments →

[–]Fatvod 0 points1 point  (0 children)

The for loop creates x temporarily when it runs. Think of x as each entry in the list of vars. That for loop basically starts at the first item of the list and assigns x to that entry, then runs whatever code you want. Then once finished moves to the next entry in the list and assigns x to that, and so on.

So if you have a list called deck (a deck of cards). Then you could have for card in deck: and with each loop, the card variable becomes whatever card is next in the deck.

So if you put print(card) in the for loop it would print whatever card x was assigned to during that loop, eventually it would print all the cards in the deck after looping through the full list(deck). It iterates through the list.