Apr-09-2020, 02:31 PM
Yes the loop variable can be called whatever you want.
The only job it has is to take on the value of the next element in
A general rule if the
The only job it has is to take on the value of the next element in
iterable
each time through the loop.A general rule if the
iterable
data collection has some stuff that can be given useful loop variable name,then do that.>>> colors = ['Red', 'Blue', 'Green'] >>> for color in colors: ... print(color) ... Red Blue GreenIs clearer than.
>>> colors = ['Red', 'Blue', 'Green'] >>> for rubberduck in colors: ... print(rubberduck) ... Red Blue Green