How do I create a list with numbers between two values?
Here is an example of how you might create a list of numbers between two values in python:
start = 5
end = 10
my_list = list(range(start, end))
print(my_list)
# Output: [5, 6, 7, 8, 9]
In this example, the range(start, end)
function generates a sequence of numbers from start
up to, but not including, end
. The list()
function is then used to convert the range to a list.
Alternatively, a list comprehension can also be used to achieve this:
You can also generate a list of numbers with a specific step between each number using range function
Where step is the value to increment.