Python Forum
what does x reprsent in this code ?
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
what does x reprsent in this code ?
#6
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 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
Green
Is clearer than.
>>> colors = ['Red', 'Blue', 'Green']
>>> for rubberduck in colors:
...     print(rubberduck)    
...     
Red
Blue
Green
Reply


Messages In This Thread
RE: what does x reprsent in this code ? - by buran - Apr-09-2020, 02:25 PM
RE: what does x reprsent in this code ? - by snippsat - Apr-09-2020, 02:31 PM
RE: what does x reprsent in this code ? - by buran - Apr-10-2020, 07:20 PM
RE: what does x reprsent in this code ? - by buran - Apr-19-2020, 01:49 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020