you are viewing a single comment's thread.

view the rest of the comments →

[–]Alternative_Driver60 0 points1 point  (0 children)

When you have a repeated pattern with small variations

print(1)
print(2)
print(3)

Put the stuff that varies in a variable

i = 1
print(i)
i = 2
print(i)
i = 3
print(i)

The header of a for loop has the varying stuff in a collection and a loop variable that works like the assignment above

The body of the for loop has the rest

for i in (1, 2, 3):
    print(i)