0
I didnt understand why "word" is there in the 2nd line ? Its not even defined..
words = ["hello", "world", "spam", "eggs"] for word in words: print(word + "!")
5 odpowiedzi
+ 3
word is the name of a for loop varibale. It does not need to be defined. it holds in easch iteration of the loop one word, starting from the left side of the list words. next iteration will give next element from words list, and so on. The loop has as many iterations as the list has elements.
inside the loop you can no do something with the content of word.
0
Becoz it is words not not word
I thunk u forget s in last of word
0
word could be anything.
for i in words:
print(i + '!')
Would do the same, its just assigning a variable to each word on the fly. wich is overwritten with each word every turn in the iteration
0
Word represents where you are in the loop so that you can make the loop do different things for each run through.
0
It's basically used to iterate in loop
it can be any name variable , depends on u.