Skip to Content
Learn
Lists and Functions
Passing a range into a function

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:

  1. range(stop)
  2. range(start, stop)
  3. 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].

Folder Icon

Take this course for free

Already have an account?