+ 2

I don't understand 'word' in this program.

words = ["hello", "world", "spam", "eggs"] for word in words: print(word + "!") for 'word', what is this??

28th Jan 2018, 3:41 PM
Rohan
Rohan - avatar
6 Answers
+ 2
This one really helped, because I am learning java.
29th Jan 2018, 12:57 AM
Rohan
Rohan - avatar
+ 1
thankyou
28th Jan 2018, 3:46 PM
Rohan
Rohan - avatar
+ 1
So, the 'word' is like a variable, I suppose.
28th Jan 2018, 3:49 PM
Rohan
Rohan - avatar
+ 1
its just like you saying for a number in (1/2/3/4)
28th Jan 2018, 4:45 PM
Android Boi
Android Boi - avatar
+ 1
It means for every word inside the "words" array. you can replace "word" with anything you want. like item
28th Jan 2018, 6:13 PM
Ismael Kedir
Ismael Kedir - avatar
+ 1
Equivalent would be string[] words = ["hello","world","spam","eggs"] for (int i=0;i < words.length; i++){ string word = words[i] print(word+"!") } foreach more or less does that for you.
28th Jan 2018, 6:14 PM
Denis Jay