Lesson 21 of 55
9 mins readPython Arithmetic Sequences & List Ranges
In Plain English
Construct arithmetic sequences effortlessly: [start..end], [start, next..end] for step intervals, and unbounded infinite streams [1..] powered by lazy evaluation.
Deep Dive: How It Works
Unit Ranges: [1..5] evaluates to [1, 2, 3, 4, 5].
Step Ranges: [2, 4..10] detects step difference 4 - 2 = 2 and generates [2, 4, 6, 8, 10].
Infinite Ranges: [1..] generates an infinite stream. When paired with take (e.g. take 5 [1..]), only the first 5 are computed.
Core Rules to Remember

Step Deduction: Provide two initial elements [1, 3..9] to set the step spacing automatically.

Infinite Streams: take 10 [1..] extracts items from an unbounded sequence without hanging.
Live Interactive Example
Hit Run Code to see it liveRanges and Infinite Sequence Evaluation
Python 3.12
1
2
3
4
5
6
7
8
9
10
11
12
Output Console
Click "Run Code" to view the rendered output.
How it works: take 5 safely consumed 5 items from the infinite stream.
Your Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Micro Exercise
Generate Multiples of 5
Take the first `4` multiples of 5 with `take 4 [5, 10..]`.
Print `"Multiples: "` followed by the result.
1
2
3
4
5
6
Sandbox Output
Click "Run & Check" to test your solution.
Finished reading and practicing?
Mark this lesson as completed to update your course progress.