for loops | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

for loops

words = ["hello", "world", "spam", "eggs"] counter = 0 max_index = len(words) - 1 while counter <= max_index: word = words[counter] print(word + "!") counter = counter + 1 what does the [counter] in the 6th line represent? or why do we have to put it there? .please explain.

8th Oct 2018, 9:17 PM
Aws Poseidon
Aws Poseidon - avatar
1 Answer
+ 2
The Counter represents the Index of an Item in the List Words. https://www.sololearn.com/learn/JUMP_LINK__&&__Python__&&__JUMP_LINK/2431/ But this is a realy complicated Solution. You can reach the same Output with: words = ["hello", "world", "spam", "eggs"] for word in words: print(word + "!")
8th Oct 2018, 9:40 PM
Sebastian Keßler
Sebastian Keßler - avatar