0

Replace word with words

Can someone please explain why i'm getting the same answer when replace word in the original code with words ? words = ["hello", "world", "spam", "eggs"] for words in words: print(words + "!")

21st May 2019, 7:10 AM
Ranil Fernando
Ranil Fernando - avatar
3 Réponses
+ 1
words = ["hello", "world", "spam", "eggs"] for word in words: print(word + "!") loop index cannot be the same name with the name of list ------------------------ Moreover, you don't replace .. just print elements adding exclamation mark
21st May 2019, 7:15 AM
Prokopios Poulimenos
Prokopios Poulimenos - avatar
+ 1
There is no need to define it. The scope of this variable/index is only inside the loop
21st May 2019, 7:51 AM
Prokopios Poulimenos
Prokopios Poulimenos - avatar
0
So the word here is the loop index, but why that wasn't defined before ?
21st May 2019, 7:40 AM
Ranil Fernando
Ranil Fernando - avatar