Skip to content
Skip to resources
peazit

What do you want to understand today?

PEAZIT Aha card

The range loop: the stop value is excluded

Go straight to resources ↓

range(start, stop) produces integers from start inclusive to stop exclusive, normally in steps of one. for assigns each value in turn and runs its indented body.

The range loop: the stop value is excluded
ObservationWhat it means
range(3)0, 1, 2
range(2, 5)2, 3, 4

One worked example

  1. s = 0Prepare a total.
  2. for i in range(1, 4): s = s + iAdd 1, then 2, then 3.
  3. s = 6The upper bound 4 is not added.

Watch out: A third range argument changes the step; negative steps need suitable bounds. break can end a loop early.

Goal, prerequisites and card origin

What you will learn: Count repetitions of a Python for loop.

What you need first: Integers and assignment.

An original PEAZIT working card. Independent expert review and effectiveness testing have not yet taken place. · v1

Reference for the underlying principle ↗
Show connections

range(start, stop) produces integers from start inclusive to stop exclusive, normally in steps of one. for assigns each value in turn and runs its indented body.

Other options for this topic

Catalogue

Nothing here just yet.

Try a shorter search, another language or fewer filters.

Clear filters

Find your own way. Resources open directly on their authors’ websites. Order reflects search relevance, not a teaching-quality rating.

47,636 resources to explore

15 independent sources

3 resource languages

EXPLORE / EN

Where will curiosity take you?

Start with a subject. Then find your way.

All topics
peazit

Everyone learns differently. Find your way.

Saved

For your next aha.

Your saved links stay in this browser.