How to Create a List of Numbers from 1 to 10 in Python?

16-May-2023

.

Admin

How to Create a List of Numbers from 1 to 10 in Python?

Hi Dev,

In this post, we will learn to create a list of numbers from 1 to 10 in a Python tutorial example. Here you will learn Python to create a list of 1 to 10 numbers. you will learn to create a list of numbers from Python 1 to 10. This article goes into detail on how to create a list from 1 to 10 in Python. Follow the below tutorial step of Python to create a list of numbers from 1 to 10.

If you are looking to generate a list of numbers from 1 to 10 in Python, there are several ways to create a list from 1 to 10 in Python. here, I will give you two examples with range() and numpy library for creating new list numbers from 1 to 10 in Python. so, let's see the example code.

Example 1:


main.py

# python create list 1 to 10 of numbers

myList = list(range(1, 11))

print(myList)

Output:

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

Example 2:

main.py

import numpy as np

# python create list of numbers from 1 to 10

myList = np.arange(1, 11, 1).tolist()

print(myList)

Output:

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

#Python