0
Python: for loops
Below is the code, I don't understand how and why "word" came out of nowhere. Does "for' accomplishes the same thing as "while"? words = ["hello", "world", "spam", "eggs"] for word in words: print(word + "!")
3 RĂ©ponses
+ 4
"for word in words"
Is a specific python syntax to access all items of a list one by one. You can use any variable name instead of "word".
You can also replace it by
"for i in range (len(words))"
It will do the same. But "for word in words" looks clean and easier to understand
+ 2
Output
hello!
world!
spam!
eggs!
It's because for loop in words .
+ 1
Thank you very much!