0

What is word in words

Where exactly does the variable word come from? It doesn't match words

2nd Oct 2020, 2:05 AM
Dammy Adebayo
Dammy Adebayo - avatar
2 RĂ©ponses
+ 7
In a for loop, you go through an array of things (like a list of words or a string of characters) one element at a time. You need to temporarily give the elements a name so that you can do something with them. You can use any name you want, but descriptive names are preferred to help the reader understand what's going on. "for word in words" and "for char in string" are common, but if you wanted to say "for x in words" or "for potato in words", they would work just as well. 🙂
2nd Oct 2020, 3:30 AM
David Ashton
David Ashton - avatar
+ 2
That means we iterate through words, using word variable. If we have a words list assigned ["Solo, "Learn", 42] for word in words will loop 3 times. Each time word is an element of words. 1st time word is "Solo", 2nd time is "Learn", and 3rd time is 42.
2nd Oct 2020, 2:41 AM
äœ çŸ„é“èŠć‰‡ïŒŒæˆ‘äčŸæ˜Ż
äœ çŸ„é“èŠć‰‡ïŒŒæˆ‘äčŸæ˜Ż - avatar