+ 2
words = ["hello", "world", "spam", "eggs"] for word in words: print(word + "!")
so question is that is the word predefined variable which directly points to the string in the list?
4 Respostas
+ 2
Is it predefined or is it like we can use any variable instead of word?
+ 1
word is a variable that will point to every word in that list, as the loop goes on.
So basically as if you write:
word = words[0]
print(word+'!')
word = words[1]
print(word+'!')
... and so on.
+ 1
You can use any word that would be okay as a variable name too (because it is one).
So you could write:
for fruit in fruitBasket:
for word in vocabulary:
for book in bookShelf:
for n in range(100):
It's totally your choice.
Whatever you choose, it just becomes a normal variable, that you can even continue to use after the loop.
0
Ohh... Thanks alot