0

How does the compiler know what dot is and if you replace dit with other words it still works why?

words = ["hello", "world", "spam", "eggs"] for dot in words: print(dot + "!")

3rd Dec 2016, 2:32 AM
Racho Ivanov
Racho Ivanov - avatar
2 Réponses
+ 1
Dot is a variable which refers to the current iteration of the list. So, you'd access that the same way you'd access everything else. @donkeyhot Yeah. I'm just used to calling lists/arrays tables. As far as iteration in a for loop goes, I was referring to the value within a certain index in a list. Corrected myself in OP.
3rd Dec 2016, 2:51 AM
Ben
Ben - avatar
+ 1
dot is just a name of your variable. You can name it whatever you like, even gigantic_alien_pizza. In your code, it iterates through words list. @Ben, it's called a list, not a table. And iterating a for loop has nothing to do with indexes.
3rd Dec 2016, 11:11 AM
donkeyhot
donkeyhot - avatar