1. Learn
  2. /
  3. Courses
  4. /
  5. Drag and Drop Examples

Connected

Exercise

(SAMPLE CODING) Built-in practice: range()

In this exercise, you will practice using Python's built-in function range().

Remember that we can use range() in two different ways:

(1) Create a sequence of numbers from 0 to (stop - 1). This is useful when we want to create a simple sequence of numbers starting at zero:

range(stop)

# Example
list(range(11))

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

(2) Create a sequence of numbers from start to (stop - 1) with a step size. This is useful when we want to create a sequence of numbers that increments by some value other than one. For example, a list of even numbers:

range(start, stop, step)

# Example
list(range(2,12,2))

[2, 4, 6, 8, 10]

Instructions

100 XP
  • Create a range object that starts at zero and ends at five. Only use a stop argument.
  • Print the data type of the nums variable.
  • Convert the nums variable into a list called nums_list.
  • Create a new list called nums_list2 by unpacking the nums variable using the star character (*).