8. Range start stop

The two-argument form of range() sets where the sequence starts and where it stops:

  • start — first number. Included.
  • stop — number where the sequence stops. Excluded.
  • The step is still 1.

If start is greater than or equal to stop, the sequence is empty and the loop body never runs.

#01

Set the start

Loop over range(1, 4) and print each number.

Print exactly:

Create a free account to save your progress and unlock chapter 2.

#02

Move the whole range

Loop over range(3, 7) and print each number.

Print exactly:

Create a free account to save your progress and unlock chapter 2.

#03

Build labels from a range

Loop over range(10, 13) and print Page <n> for each number using an f-string.

Print exactly:

Create a free account to save your progress and unlock chapter 2.

#04

Use negative numbers

Loop over range(-2, 2) and print each number.

Print exactly:

Create a free account to save your progress and unlock chapter 2.