+ 1

For loop logic

Sytax:- words = ["hello", "world", "spam", "eggs"] for word in words: print(word + "!") Output:- hello! world! spam! eggs! My doubt is list name is words where as while printing we mentioned as (word + "!") so how system read this statement to print values?

17th Sep 2020, 6:51 PM
Abhi
Abhi - avatar
2 Answers
+ 4
You can use any letter or word in for loops. Here, the word used is 'word'.
17th Sep 2020, 7:08 PM
Pranav
Pranav - avatar
0
for not to confuse, use other name like x for x in words : print( x + "!") x is assigned like x = words[0] Next x = words[1] x = words[2] x = words[3] .. Upto words length..
17th Sep 2020, 8:13 PM
Jayakrishna 🇼🇳