+ 1
For and in
So the code goes like this: words = ["hello", "world", "spam", "eggs"] for word in words: print(word + "!") I was under the impression that âinâ referenced something âinâ the list, but âwordâ isnât in the list? Is âforâ assigning the âwordsâ list to âwordâ for the print command? Please explain how you would to a toddler, Iâm very new to this Thanks!
3 Answers
+ 5
word is the variable you assign for objects in the list.
+ 6
You could substitute 'x' for 'word' and 'y' for 'words' and get exactly the same output. It's just better coding style to use variable names that explain what's happening, which makes the code more readable.