+ 1
words = ["hello", "world", "spam", "eggs"] for word in words: print(word + "!")
I don't understand that .. what the value (purpose)of "word"in that program..
4 Respuestas
+ 7
word is a placeholder of sorts. The for loop iterates over the list and for each iteration word takes the value of the next item.
For the first iteration word is "hello" for the second word is "world" and so on down to the last iteration where word is "eggs".
NOTE: It is not mandatory to use word, you can use another name like "item"
+ 5
It is foreach loop. It is saying thing like: For every word in words array, print word to the screen. Word is each word in words array.
+ 2
Tq friends
0
DM your answer's