+ 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?

11th Aug 2019, 11:12 AM
Hrishikesh Dherange
Hrishikesh Dherange - avatar
4 Respostas
+ 2
Is it predefined or is it like we can use any variable instead of word?
11th Aug 2019, 12:18 PM
Hrishikesh Dherange
Hrishikesh Dherange - avatar
+ 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.
11th Aug 2019, 11:29 AM
HonFu
HonFu - avatar
+ 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.
11th Aug 2019, 12:21 PM
HonFu
HonFu - avatar
0
Ohh... Thanks alot
11th Aug 2019, 12:43 PM
Hrishikesh Dherange
Hrishikesh Dherange - avatar