+ 3
How this code work and what is "word" here?
words = ["hello", "world", "spam", "eggs"] for word in words: print(word + "!")
4 Respostas
+ 4
word is an iterator here. Just by convention you can use a singular form of a noun for the iterator and plural for the iterated set.
But it could as well be "for x in y" - with the same effect.
+ 2
in your code, you stored 4 words (hello, world, spam and eggs) as array elements into an array variable called "words". The "for" keyword will loop through each elements in order to print them out.
+ 2
what is the word "word"do here
+ 1
It is just a temporary variable to hold the values for each iteration of your array.