Various ways to create an array of numbers from 1 to 10 in Python.

I will write how to create an array of numbers from 1 to 10 in Python. I look forward to working with you.

First, the basic array method.

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

Next, the method using the for statement.

a = []
for i in range(1, 11):
  a.append(i)
a = [0]*10
for i in range(10):
  a[i] = i+1

Method using while.

a = []
i = 1
while len(a) < 10:
  a.append(i)
  i += 1
a = [0]*10
i = 0
while not all(a):
  a[i] = i+1
  i += 1

Finally, the method of inclusion notation.

a = [i for i in range(1, 11)]

that's all. Thank you very much.

Recommended Posts

Various ways to create an array of numbers from 1 to 10 in Python.
Create an instance of a predefined class from a string in Python
How to create an instance of a particular class from dict using __new__ () in python
[Python] List Comprehension Various ways to create a list
Various ways to read the last line of a csv file in Python
Quicksort an array in Python 3
Various ways to extract columns in a NumPy array
How to create an image uploader in Bottle (Python)
I tried to create API list.csv in Python from swagger.yaml
How to slice a block multiple array from a multiple array in Python
How to swap elements in an array in Python, and how to reverse an array.
Various ways to calculate the similarity between data in python
[Django] Memo to create an environment of Django + MySQL + Vue.js [Python]
Create folders from '01' to '12' with python
6 ways to string objects in Python
Law of large numbers in python
5 Ways to Create a Python Chatbot
An alternative to `pause` in Python
How to know the internal structure of an object in Python
How to make a string into an array or an array into a string in Python
I tried to create a list of prime numbers with python
How to create a heatmap with an arbitrary domain in Python
Summary of various for statements in Python
Various ways to create a dictionary (memories)
Python> Output numbers from 1 to 100, 501 to 600> For csv
Convert from Markdown to HTML in Python
Started Python: Swap an array of values obtained from SQL results to a list type and use it in IN of another query
Create an empty array in Numpy to add rows for each loop
Extract every n elements from an array (list) in Python and Ruby
I want to color a part of an Excel string in Python
[Python] [Word] [python-docx] Try to create a template of a word sentence in Python using python-docx
An example of the answer to the reference question of the study session. In python.
Edit Excel from Python to create a PivotTable
Create a C array from a Python> Excel sheet
Summary of how to import files in Python 3
I want to create a window in Python
[Python pandas] Create an empty DataFrame from an existing DataFrame
From file to graph drawing in Python. Elementary elementary
How to create a JSON file in Python
Create an environment of 64bit Windows + python 2.7 + MeCab 0.996
[python] Create table from pandas DataFrame to postgres
Summary of how to use MNIST in Python
Create an image with characters in python (Japanese)
Create a datetime object from a string in Python (Python 3.3)
Output in the form of a python array
Project Euler # 13 "Sum of Large Numbers" in Python
Speed: Add element to end of Python array
Randomly select elements from list (array) in python
An easy way to call Java from Python
[python] What to do when an error occurs in send_keys of headless chrome
Let Code Day21 Starting from Zero "448. Find All Numbers Disappeared in an Array"
Create a setting in terraform to send a message from AWS Lambda Python3.8 to Slack
How to create an article from the command line
The wall of changing the Django service from Python 2.7 to Python 3
Summary of tools needed to analyze data in Python
Operate mongoDB from python in ubuntu environment ① Introduction of mongoDB
How to get the number of digits in Python
Changes from Python 3.0 to Python 3.5
Convert NumPy array "ndarray" to lilt in Python [tolist ()]
Changes from Python 2 to Python 3.0
[Blender x Python] How to create an original object