Sometimes you need to walk a sequence of numbers that doesn't exist yet, do this five times, count from 1 to 100. Python generates it with range. JavaScript has no direct equivalent; it uses a counting for-loop instead (Module 12) or builds an array.
range(5) produces 0, 1, 2, 3, 4, five numbers, starting at 0, stopping before 5. The same start-included, end-excluded rule as slicing.
Generating number sequences
PYTHON
print(list(range(5))) # 0 to 4
print(list(range(1, 6))) # 1 to 5
print(list(range(0, 10, 2)))# step by 2
≈
JAVASCRIPT
// JavaScript has no range. Build it,
// or count in a loop.
console.log([0, 1, 2, 3, 4]);
console.log(
Array.from({length: 5}, (_, i) => i + 1)
);
console.log([0, 2, 4, 6, 8]);
Compare → This is a LANGUAGE-SPECIFIC FEATURE. Python's range is a clean built-in; JavaScript reaches for a counting loop or Array.from. Don't force a false equivalence, just know that both languages can walk a sequence of numbers, by different means.
EXAMPLE
loading editor…
YOUR TURN
Your turn → range(2, 7) starts AT 2 and stops BEFORE 7, five numbers. In the Python tab, add a line that uses range to print the numbers 1 through 10.
loading editor…
Syntax has to be exact. Every quote, bracket and parenthesis needs its partner, and in Python the spaces at the start of a line count. One slip and the program won't run; the message will say where.
✦ The bridge to Module 12
Everything walkable, lists, strings, dictionary keys, sets, ranges, plugs into exactly one piece of syntax: the for-loop. You've now met every structure it works on. Next module, you learn the loop itself, and all of this becomes automatic.
◈ Graded Challenge
Create stations as a list of four radio station names, station_count holding how many there are, first_station holding the first one, and letters holding how many characters are in the word Sankofa.
Name it exactly: stations, station_count, first_station, letters
3 visible + 1 hidden
loading editor…
Mark this lesson complete
Signed in, your progress follows you to every device.