0
for loops
Hello! I have the next code: words = ["hello", "world", "spam", "eggs"] for word in words: print(word + "!") But I do not understand exatly what is mean. Cand someone explain for me step by step? Thank you!
5 Answers
+ 2
Ok. Let's imagine that every item in the list is laying somewhere, for example in a basket.
The code grabs every item, prints it with a "!" and puts it somewhere else. It always grabs them in the order, because they are laying one on top of each other.
If you still don't understand, I can explain even simpler.
+ 2
Here is something i did a few weeks ago: Understanding a for loop:
https://code.sololearn.com/cu1c6tKg4ev1/?ref=app
+ 1
The first line creates a list called 'words' of 4 strings
The second statement is splitted into two lines:
The first line begins a for loop to iterate through the list and assign the values to the variable 'word'
The second line prints the word and appends '!' to it
https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2435/
+ 1
I think I understand now. Thank you everyone!