Elements of a list | Sololearn: Learn to code for FREE!

Elements of a list

in this example: words = ["hello", "world", "spam", "eggs"] for word in words: print(word + "!") How it knows that "word" is an element of the list? It works the same with random text: list = ["hello", "world", "spam", "eggs"] for plane in list: print(plane + "!")

16th Jan 2019, 10:00 AM
Serj Rot
Serj Rot - avatar
1 Answer
+ 1
The word in the for statement, is called an "iteration variable". It's value will be different in each cycle, taking all the values one by one from the iterator (something after the "in" keyword). The iterator can be a list, a string, a range of numbers for example.
16th Jan 2019, 2:35 PM
Tibor Santa
Tibor Santa - avatar