range()
Generates a sequence of numbers (used with for).
Syntax
range(start, end, step)
Description
Generates numbers starting at 0 (or at start) up to end (excluded). With a single argument, range(n) → 0..n-1. step is the skip amount.
Example
Loading editor…
Expected output
[0, 1, 2, 3, 4] [2, 4, 6, 8]
When to use?
A set number of repetitions, looping with an index, number tables.
Common mistakes
- ⚠️ end is not included: range(1,4) → 1,2,3.