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 + "!")
3 Answers
+ 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
+ 1
There is no need to define it.
The scope of this variable/index is only inside the loop
0
So the word here is the loop index, but why that wasn't defined before ?