How to generate a sequence of numbers in Python

0 min

It is often useful to have a sequence of numbers in Python.

Using the built-in range() method your can generate a sequence of numbers.

numbers = range(0,10)

print(numbers)
How to generate and print a sequence of number in Python

It is often used with loops like that :

for each in range(0,10):
	print(each)
How to print each value of the sequence

Adding steps

You can also add a step value, so that it doesn't increment by one but by the step value.

Here is an example

numbers = range(0,100, 20)

print(numbers)
How to increment by more than 1 each time using the step value

Here you are ! You now know how to generate a sequence of numbers in Python !