What can the iteration variable be named?

for student in students_period_A:

Thanks! Something I found very helpful was to use something arbitrary for the temporary variable. For example, in this solution, you can replace ‘student’ with ‘i’. You can’t complete the exercise that way, but it jumps out at you what ‘i’ is doing:

for i in students_period_A:
1 Like

I’m glad you pointed out that the iteration variable can have any name. It just exists to be assigned, one after the other, the items in the iterable which follows the operator in.

As time goes on, you will find that it is quite common (and, IMHO, sensible) to name the iterable with a plural noun, and the iteration variable with the singular of the same noun (or some variation thereof).


Not yet reached that stage :slight_smile:

I prefer using x or y or z for different iterator vairables.

1 Like

From your explanation, Iterable is the item in the list, while iteration variable is the name of the list, right ?

Hello @rk45!

  • Iteration is the process of going over an iterable and taking one item at a time from the iterable.
  • An iterable is anything that can be looped over (like a list or string). For example, the students_period_A in for i in students_period_A.
  • The iteration variable is a temporary variable whose value can be changed each time a loop iterates. For example, the i in for i in students_period_A:.