How to make a list of Python numbers from among

Learn how to turn a number into a list of digits in Python using a simple example.

Creating a List of Python Numbers

Creating a list of Python numbers is a great way to get started with coding. The following example will show you how to create a list of numbers using Python.


# Create a list of numbers 
list_of_numbers = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

# Print out the list 
print(list_of_numbers) 

The output should be: [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

You can also add more elements to the list if you want. For example, if you wanted to add the numbers 11 and 12, you could do the following:


# Add new numbers to the list 
list_of_numbers.append(11)
list_of_numbers.append(12)

# Print out the list 
print(list_of_numbers) 

The output should be: [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]

You can also use the extend() method to add multiple elements to the list. For example, if you wanted to add the numbers 13, 14, and 15, you could do the following:


# Add multiple numbers to the list 
list_of_numbers.extend([13, 14, 15])

# Print out the list 
print(list_of_numbers) 

The output should be: [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]

You can also use the range() function to create a list of numbers. For example, if you wanted to create a list of numbers from 1 to 10, you could do the following:


# Create a list of numbers from 1 to 10 
list_of_numbers = list(range(1, 11))

# Print out the list 
print(list_of_numbers) 

The output should be: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Using the range() function is a great way to quickly create a list of numbers. You can also use it to create a list of numbers from a certain number to another number. For example, if you wanted to create a list of numbers from 5 to 10, you could do the following:


# Create a list of numbers from 5 to 10 
list_of_numbers = list(range(5, 11))

# Print out the list 
print(list_of_numbers) 

The output should be: [5, 6, 7, 8, 9, 10]

As you can see, creating a list of Python numbers is easy. There are many different ways to do it, so you can choose the one that works best for your project.

Answers (0)