+ 1

If Im using a loop "for in" didnt I have to declare variable? Like: words = ["hello", "world", "spam", "eggs"] for word in words: print(word + "!") variable word is not declared..

24th Aug 2016, 7:34 PM
Yurith gonçalves
Yurith gonçalves - avatar
2 Answers
+ 3
of course, you have to tell python, through what to make a for loop in statement "for word in words": "word" is a name of a dynamic variable, created only for this loop "words" is a name of iterable object, like list, tuple, string, range etc. it must be declared before or right now (like range) to use it properly in loop
24th Aug 2016, 7:48 PM
Demeth
Demeth - avatar
0
Great tnx!
24th Aug 2016, 8:00 PM
Yurith gonçalves
Yurith gonçalves - avatar