How can I generate a list of consecutive numbers?

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How can I generate a list of consecutive numbers in Python. So Here I am Explain to you all the possible Methods here.

How can I generate a list of consecutive numbers?

1. How can I generate a list of consecutive numbers?

Here is a way to generate n consecutive numbers in equal intervals between them starting from 0 to 100 using numpy:
import numpy as np myList = np.linspace(0, 100, n)

2. generate a list of consecutive numbers

Here is a way to generate n consecutive numbers in equal intervals between them starting from 0 to 100 using numpy:
import numpy as np myList = np.linspace(0, 100, n)

Method 1

Using Python’s built in range function:

Python 2

input = 8
output = range(input + 1)

print output
[0, 1, 2, 3, 4, 5, 6, 7, 8]

Python 3

input = 8
output = list(range(input + 1))

print(output)
[0, 1, 2, 3, 4, 5, 6, 7, 8]

Method 2

Here is a way to generate n consecutive numbers in equal intervals between them starting from 0 to 100 using numpy:

import numpy as np

myList = np.linspace(0, 100, n)

Conclusion

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.