+ 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?
2 Answers
+ 4
You can use any letter or word in for loops. Here, the word used is 'word'.
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..