python> array> Determine the number and initialize> mylist = [idx for idx in range (10)] / mylist = [0 for idx in range (10)] >> mylist = [0] * 10

I wasn't sure how to declare it as an array of size N in python.

http://www.i-programmer.info/programming/python/3942-arrays-in-python.html?start=1 The way I understood by reading this area.

try1

http://ideone.com/3oPLwu

test.py


mylist = [idx for idx in range(10)]
print mylist

result


Success	time: 0.03 memory: 44680 signal:0
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

With this, 100 arrays can be initialized for the time being.

If you want to set the initial value to 0, it seems that you should set the leftmost idx to 0.

mylist = [0 for idx in range(10)]

improved (Added on 2015/12/01)

If you just want to initialize, the following method that you both told us in the comments is simple and easy to see.

mylist = [0] * 10

Please refer to @ shiracamus's comment (2015/12/01 07:41) for notes on range ().

Recommended Posts

python> array> Determine the number and initialize> mylist = [idx for idx in range (10)] / mylist = [0 for idx in range (10)] >> mylist = [0] * 10
About "for _ in range ():" in python
Check the processing time and the number of calls for each process in python (cProfile)
Get the MIME type in Python and determine the file format
Determine the date and time format in Python and convert to Unixtime
Count the number of Thai and Arabic characters well in Python
MongoDB for the first time in Python
[Python] Combine all the elements in the array
CERTIFICATE_VERIFY_FAILED in Python 3.6, the official installer for macOS
Output the number of CPU cores in Python
plot the coordinates of the processing (python) list and specify the number of times in draw ()
Prime number enumeration and primality test in Python
Divides the character string by the specified number of characters. In Ruby and Python.
Specifying the range of ruby and python arrays
[Python] Precautions when finding the maximum and minimum values in a numpy array with a small number of elements
About the difference between "==" and "is" in python
Tips for hitting the ATND API in Python
Output in the form of a python array
I want to get the file name, line number, and function name in Python 3.4
Get the last element of the array by splitting the string in Python and PHP
Automate background removal for the latest portraits in a directory with Python and API
Rock-paper-scissors poi in Python for beginners (answers and explanations)
Check if the string is a number in python
Receive the form in Python and do various things
How to get the number of digits in Python
[Python] Measures and displays the time required for processing
Determine the threshold using the P tile method in python
Carefully understand the exponential distribution and draw in Python
Preferences for playing Wave in Python PyAudio and PortAudio
Visualize the range of interpolation and extrapolation with python
Problems and countermeasures for Otsu's binarization overflow in Python
Plot and understand the multivariate normal distribution in Python
Carefully understand the Poisson distribution and draw in Python
Get the size (number of elements) of UnionFind in Python
Find the Hermitian matrix and its eigenvalues in Python
Recursively search for files and directories in Python and output
About Python, for ~ (range)
Prime number 2 in Python
Parse the Researchmap API in Python and automatically create a Word file for the achievement list
How to swap elements in an array in Python, and how to reverse an array.
Sort and output the elements in the list as elements and multiples in Python.
Get the number of specific elements in a python list
Python --Find out number of groups in the regex expression
Tips for coding short and easy to read in Python
Search for variables in pandas.DataFrame and get the corresponding row.
[Understand in the shortest time] Python basics for data analysis
Manipulate the clipboard in Python and paste the table into Excel
Useful tricks related to list and for statements in Python
[Homology] Count the number of holes in data with Python
I tried programming the chi-square test in Python and Java.
[Python] Display the elapsed time in hours, minutes, and seconds (00:00:00)
Get the current date and time in Python, considering the time difference
Get the number of occurrences for each element in the list
Problems and solutions when asked for MySQL db in Python 3
[Tips] Problems and solutions in the development of python + kivy
Google search for the last line of the file in Python
Graph the Poisson distribution and the Poisson cumulative distribution in Python and Java, respectively.
The story of returning to the front line for the first time in 5 years and refactoring Python Django
Python memo (for myself): Array
Quicksort an array in Python 3
Empty multidimensional array in python