+ 3

words=["o","my","god"] i=0 index=len(words)-1 for word in words: if i<=index: print(words[i])

If we change words with word in print statement ,the difference between the two codes

13th Jan 2019, 5:32 PM
Hari Krishna Sahu
Hari Krishna Sahu - avatar
1 Respuesta
+ 6
"for word in words", indicates that words is a list and since you decided to go with var "word" , word is iterated as o , my , god. (basically assigning o , my , god to word as the loop proceeds) So if you want to print word[i], the output will be the 1st letter of word, since i=0. Output: o m g You can use the code playground for better understanding.. play around with the variables a little bit.
13th Jan 2019, 6:02 PM
Frost
Frost - avatar