All courses › Programming with Python › for loop and range
for loop and range
A for loop repeats code for each element in a sequence, often built with range(start, stop, step). The stop value is never included itself. Without start and step, range begins at 0 and counts up by 1.
the numbers up to but not including
Symbols
| start value (included) | ||
| stop value (not included) | ||
| step |
Example
for i in range(2, 8, 2): print(i)
prints 2 4 6 — 8 is not included.
The number of iterations of
Practise loops and conditions for free →
range(a, b, s) is .