Learn
Okay! Range time. The Python range()
function is just a shortcut for generating a list, so you can use ranges in all the same places you can use lists.
range(6) # => [0, 1, 2, 3, 4, 5] range(1, 6) # => [1, 2, 3, 4, 5] range(1, 6, 3) # => [1, 4]
The range
function has three different versions:
range(stop)
range(start, stop)
range(start, stop, step)
In all cases, the range()
function returns a list of numbers from start
up to (but not including) stop
. Each item increases by step
.
If omitted, start
defaults to 0
and step
defaults to 1
.
Instructions
1.
On line 6, replace the ____
with a range()
that returns a list containing [0, 1, 2]
.
Take this course for free
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.