+ 1
for word in words: What is "word" in this example?
How can Python know what this variable means? We didn't assigned its value.
3 Respuestas
+ 3
for the 1st iteration word=words[0]
for the 2nd iteration word=words[1]
and so on it's nothing but a temporary variable
+ 1
In python, while using the for loop, it automatically creates the variable for you and assigns every element in the array to it. In this case, word is a random variable chosen. It could have been anything like, tuna, potato, apple, and still the result would have been the same.
0
it's arbitrary. they could have used any variable name to hold the current value of the list. Similar syntax is used in other scripting language such as bash.