+ 1

How the program on for loop page is working

for word in words print(word +"!")

10th Jan 2017, 4:17 PM
ayush saxena
ayush saxena - avatar
2 Answers
0
It prints every String of a String array and when they have no whitespace before they will be printed without
10th Jan 2017, 4:36 PM
Andreas K
Andreas K - avatar
0
for word in words: print(word + "!") 'words' is a list and 'word' takes the place of each item in the list in turn. A list of ["spam","eggs","foo","bar"] On the first iteration 'word' takes the first element of the list, in this case its "spam". It then prints it whilst concatenating "!" To the end. Then its the second iteration and 'word' takes "eggs" etc etc until there are no elements left in the list to loop through
10th Jan 2017, 8:52 PM
Jonah Burnswell
Jonah Burnswell - avatar