for student in students_period_A: students_period_B.append(student) print(student)
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: students_period_B.append(i) print(i)```
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
I prefer using x or y or z for different iterator vairables.
From your explanation, Iterable is the item in the list, while iteration variable is the name of the list, right ?
- 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
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
for i in students_period_A:.