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!

10th May 2020, 1:36 PM
Sebastian Ioan
Sebastian Ioan - avatar
5 Respuestas
+ 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.
10th May 2020, 2:36 PM
Antonio 👑
Antonio 👑 - avatar
+ 2
Here is something i did a few weeks ago: Understanding a for loop: https://code.sololearn.com/cu1c6tKg4ev1/?ref=app
10th May 2020, 6:59 PM
Lothar
Lothar - avatar
+ 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/
10th May 2020, 1:41 PM
Ore
Ore - avatar
+ 1
I think I understand now. Thank you everyone!
10th May 2020, 4:14 PM
Sebastian Ioan
Sebastian Ioan - avatar