What are the valid numbers that can be used for range()?


#1

Question

For this exercise, the range() function is given a number and returns a list starting at 0 and including up to the number before the one provided. What are the valid numbers that can be passed to range()?

Answer

You can pass any valid integer number to the range() function. If the number 0 or a negative number is used, the range() function will return an empty list. Otherwise, the function will return a list starting at 0 including each number up to the number before the one passed.

# These are all valid parameters to pass
example1 = range(1)
example2 = range(30000)

# These will return an empty list
nonumber1 = range(0)
nonumber2 = range(-10)

# Passing a decimal number will return a Python TypeError
error1 = range(3.2)