+ 3

How this code work and what is "word" here?

words = ["hello", "world", "spam", "eggs"] for word in words: print(word + "!")

24th Feb 2017, 5:12 PM
Uday
Uday - avatar
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.
24th Feb 2017, 8:08 PM
Kuba Siekierzyński
Kuba Siekierzyński - avatar
+ 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.
24th Feb 2017, 5:24 PM
Alex Soh Chye Wat
Alex Soh Chye Wat - avatar
+ 2
what is the word "word"do here
24th Feb 2017, 5:25 PM
Uday
Uday - avatar
+ 1
It is just a temporary variable to hold the values for each iteration of your array.
24th Feb 2017, 5:39 PM
Alex Soh Chye Wat
Alex Soh Chye Wat - avatar