+ 5
words = ["hello", "world", "spam", "eggs"] for word in words: print(word + "!")
In this what does 'for word in words' mean?
1 Answer
0
In this case, the variable "word" is meant to loop through each element in the "words" array until there are no more elements left to loop through.
For the first 2 iterations, it would look like this:
word = words[0] #Which is hello
print(word + "!") #Outputs hello!
word = words[1] #Word now equals world
print(word + "!") #Outputs world!