You can use:

>>> lst = [None] * 5
>>> lst
[None, None, None, None, None]
Answer from samplebias on Stack Overflow
๐ŸŒ
AskPython
askpython.com โ€บ python โ€บ array โ€บ initialize-a-python-array
3 Ways to Initialize an Array in Python - AskPython
3 weeks ago - The multiplication expression creates the requested initial number of elements, and later append operations can change the length. If the number of entries is calculated at runtime, keep that calculation separate so the intended size is clear and can be checked.
Discussions

python - Create an array of size n with initialized value - Stack Overflow
In python, it's possible to create an array of size n with [] * n or even initialize a fixed value for all items with [0] * n. Is it possible to do something similar but initialize the value with ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Add option to pre define size of list
Just like in C or Java, an option pre define the size and type of list. If we have the need to predefine the size of an array we can achieve this in Java. Java: int [] arr = new int[10] (Create a new array object of type int and size 10) Similarly, to achieve the same in python we have to use ... More on discuss.python.org
๐ŸŒ discuss.python.org
11
0
May 20, 2024
How to create a fix size list in python? - Stack Overflow
This is not an asymptotic speedup ... to first initialize your entire memory block before you overwrite with stuff you actually care about. This, if it were possible, is equivalent to something like (pseudo-code) x = list(size=10000). If you want something similar in python, you can use the numpy numerical matrix/N-dimensional-array manipulation ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Efficiently initialize 2D array of size n*m in Python 3? - Stack Overflow
I am using Python 3 and am trying to create 2D integer arrays of a known and fixed size. How can I do this? The arrays I have in mind are the Python-provided array.array, although I am not averse to More on stackoverflow.com
๐ŸŒ stackoverflow.com
People also ask

How do I initialize a 2D NumPy array with zeros?
Pass a tuple containing the row and column counts to np.zeros(), such as np.zeros((2, 3)). Specify dtype when the default floating-point type is not what you want.
๐ŸŒ
askpython.com
askpython.com โ€บ python โ€บ array โ€บ initialize-a-python-array
3 Ways to Initialize an Array in Python - AskPython
Does np.empty() create an array of zeros?
No. Numeric entries from np.empty() are uninitialized and may contain arbitrary values. Assign them before reading, or use np.zeros() when zero values are required.
๐ŸŒ
askpython.com
askpython.com โ€บ python โ€บ array โ€บ initialize-a-python-array
3 Ways to Initialize an Array in Python - AskPython
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-initialize-empty-array-of-given-length
Python - Initialize empty array of given length - GeeksforGeeks
As we know Array is a collection of items stored at contiguous memory locations. In Python, a List (Dynamic Array) can be treated as an Array. In this article, we will learn how to initialize an empty array of some given size. Let's see different Pythonic ways to create an empty list in Python ...
Published: July 12, 2025
๐ŸŒ
Kristianeschenburg
kristianeschenburg.github.io โ€บ 2019 โ€บ 08 โ€บ list-size
Quick Note: Initialize Python List With Prespecified Size - A Rambling On
August 21, 2019 - The base arrays are generally associated with a size or length parameter, that initializes the array to a certain length.
๐ŸŒ
FavTutor
favtutor.com โ€บ blogs โ€บ how-to-initialize-an-array-in-python
How to Initialize an Array in Python? (with Code) | FavTutor
January 27, 2021 - Python language has many inbuilt libraries and functions which makes our task easier and simpler in comparison to other programming languages. NumPy module is one of them. NumPy module can be used to initialize the array and manipulate the data stored in it. The number.empty() function of the NumPy module creates an array of a specified size with the default value=โ€ Noneโ€.
๐ŸŒ
pythontutorials
pythontutorials.net โ€บ blog โ€บ initialising-an-array-of-fixed-size-in-python
How to Initialize a Fixed-Size Array (or List) in Python: Empty Declaration Like C โ€” pythontutorials.net
Letโ€™s explore the most common ... simulate a fixed-size list is to initialize it with placeholder values (e.g., None, 0, or empty strings) using list multiplication or a list comprehension....
Find elsewhere
๐ŸŒ
Python Guides
pythonguides.com โ€บ initialize-an-array-in-python
How to Initialize an Array in Python?
July 16, 2026 - The simplest way to initialize an array in Python is to start with an empty list and add items later. This works well when you do not know the final size ahead of time, which matches how leave requests arrive throughout the year.
๐ŸŒ
Alledaags
alledaags.nl โ€บ home โ€บ tech basics digest โ€บ initialising an array of fixed size in python [duplicate]
Initialising an Array of Fixed Size in Python [Duplicate] โ—† Quantaweave Collective
They are both initialized with zeros. ... An easy solution is x = [None]*length, but note that it initializes all list elements to None. If the size is really fixed, you can do x=[None,None,None,None,None] as well.
Published: October 1, 2026
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ array.html
array โ€” Efficient arrays of numeric values โ€” Python 3.15.2 documentation
1 month ago - The actual size can be accessed through the array.itemsize attribute. ... A tuple with all available type codes. Changed in version 3.15: The type changed from str to tuple. ... A new array whose items are restricted by typecode, and initialized from the optional initializer value, which must be a bytes or bytearray object, a Unicode string, or iterable over elements of the appropriate type.
๐ŸŒ
Iditect
iditect.com โ€บ faq โ€บ python โ€บ initialising-an-array-of-fixed-size-in-python.html
Initialising an array of fixed size in Python
In Python, you can initialize an array (or a list) of a fixed size by using list comprehensions or by repeating a specific value.
๐ŸŒ
Career Karma
careerkarma.com โ€บ blog โ€บ python โ€บ python: initialize list of size n
Python: Initialize List of Size N: A Complete Guide | Career Karma
December 1, 2023 - We can initialize a list of size n using a range() statement. The difference between using a range() statement and the None method is that a range() statement will create a list of values between two numbers.
๐ŸŒ
i-Programmer
i-programmer.info โ€บ programming โ€บ python โ€บ 3942-arrays-in-python.html
Arrays in Python
March 19, 2012 - Programming book reviews, programming tutorials,programming news, C#, Ruby, Python,C, C++, PHP, Visual Basic, Computer book reviews, computer history, programming history, joomla, theory, spreadsheets and more.
๐ŸŒ
Python.org
discuss.python.org โ€บ python help โ€บ add option to pre define size of list
Add option to pre define size of list - Python Help - Discussions on Python.org
May 20, 2024 - Just like in C or Java, an option pre define the size and type of list. If we have the need to predefine the size of an array we can achieve this in Java. Java: int [] arr = new int[10] (Create a new array object of type int and size 10) Similarly, ...
๐ŸŒ
Quora
quora.com โ€บ In-Python-how-can-I-initialize-an-array-or-list-yet-to-be-populated-with-values-to-have-a-defined-size
In Python, how can I initialize an array (or list), yet to be populated with values, to have a defined size? - Quora
Answer: [code]a = numpy.empty(n, dtype=object) [/code]This creates an array of length n that can store objects. It can't be resized or appended to. In particular, it doesn't waste space by padding its length. This is the Python equivalent of Java's [code]Object[] a = new Object[n]; [/code]If y...
Top answer
1 of 10
131

(tl;dr: The exact answer to your question is numpy.empty or numpy.empty_like, but you likely don't care and can get away with using myList = [None]*10000.)

Simple methods

You can initialize your list to all the same element. Whether it semantically makes sense to use a non-numeric value (that will give an error later if you use it, which is a good thing) or something like 0 (unusual? maybe useful if you're writing a sparse matrix or the 'default' value should be 0 and you're not worried about bugs) is up to you:

>>> [None for _ in range(10)]
[None, None, None, None, None, None, None, None, None, None]

(Here _ is just a variable name, you could have used i.)

You can also do so like this:

>>> [None]*10
[None, None, None, None, None, None, None, None, None, None]

You probably don't need to optimize this. You can also append to the array every time you need to:

>>> x = []
>>> for i in range(10):
>>>    x.append(i)

Performance comparison of simple methods

Which is best?

>>> def initAndWrite_test():
...  x = [None]*10000
...  for i in range(10000):
...   x[i] = i
... 
>>> def initAndWrite2_test():
...  x = [None for _ in range(10000)]
...  for i in range(10000):
...   x[i] = i
... 
>>> def appendWrite_test():
...  x = []
...  for i in range(10000):
...   x.append(i)

Results in python2.7:

>>> import timeit
>>> for f in [initAndWrite_test, initAndWrite2_test, appendWrite_test]:
...  print('{} takes {} usec/loop'.format(f.__name__, timeit.timeit(f, number=1000)*1000))
... 
initAndWrite_test takes 714.596033096 usec/loop
initAndWrite2_test takes 981.526136398 usec/loop
appendWrite_test takes 908.597946167 usec/loop

Results in python 3.2:

initAndWrite_test takes 641.3581371307373 usec/loop
initAndWrite2_test takes 1033.6499214172363 usec/loop
appendWrite_test takes 895.9040641784668 usec/loop

As we can see, it is likely better to do the idiom [None]*10000 in both python2 and python3. However, if one is doing anything more complicated than assignment (such as anything complicated to generate or process every element in the list), then the overhead becomes a meaninglessly small fraction of the cost. That is, such optimization is premature to worry about if you're doing anything reasonable with the elements of your list.


Uninitialized memory

These are all however inefficient because they go through memory, writing something in the process. In C this is different: an uninitialized array is filled with random garbage memory (sidenote: that has been reallocated from the system, and can be a security risk when you allocate or fail to mlock and/or fail to delete memory when closing the program). This is a design choice, designed for speedup: the makers of the C language thought that it was better not to automatically initialize memory, and that was the correct choice.

This is not an asymptotic speedup (because it's O(N)), but for example you wouldn't need to first initialize your entire memory block before you overwrite with stuff you actually care about. This, if it were possible, is equivalent to something like (pseudo-code) x = list(size=10000).

If you want something similar in python, you can use the numpy numerical matrix/N-dimensional-array manipulation package. Specifically, numpy.empty or numpy.empty_like

That is the real answer to your question.

2 of 10
16

You can use this: [None] * 10. But this won't be "fixed size" you can still append, remove ... This is how lists are made.

You could make it a tuple (tuple([None] * 10)) to fix its width, but again, you won't be able to change it (not in all cases, only if the items stored are mutable).

Another option, closer to your requirement, is not a list, but a collections.deque with a maximum length. It's the maximum size, but it could be smaller.

import collections
max_4_items = collections.deque([None] * 4, maxlen=4)

But, just use a list, and get used to the "pythonic" way of doing things.

๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python
Initialize a List of Any Size with Specific Values in Python | note.nkmk.me
August 20, 2023 - Therefore, in most cases, it is not necessary to initialize the list in advance. If you want to initialize a list with a specific size where all elements have the same value, you can use the * operator as shown below.
Top answer
1 of 3
6

In Python, if the input is a numpy array, you can use np.lib.pad to pad zeros around it -

import numpy as np

A = np.array([[1, 2 ],[2, 3]])   # Input
A_new = np.lib.pad(A, ((0,1),(0,2)), 'constant', constant_values=(0)) # Output

Sample run -

In [7]: A  # Input: A numpy array
Out[7]: 
array([[1, 2],
       [2, 3]])

In [8]: np.lib.pad(A, ((0,1),(0,2)), 'constant', constant_values=(0))
Out[8]: 
array([[1, 2, 0, 0],
       [2, 3, 0, 0],
       [0, 0, 0, 0]])  # Zero padded numpy array

If you don't want to do the math of how many zeros to pad, you can let the code do it for you given the output array size -

In [29]: A
Out[29]: 
array([[1, 2],
       [2, 3]])

In [30]: new_shape = (3,4)

In [31]: shape_diff = np.array(new_shape) - np.array(A.shape)

In [32]: np.lib.pad(A, ((0,shape_diff[0]),(0,shape_diff[1])), 
                              'constant', constant_values=(0))
Out[32]: 
array([[1, 2, 0, 0],
       [2, 3, 0, 0],
       [0, 0, 0, 0]])

Or, you can start off with a zero initialized output array and then put back those input elements from A -

In [38]: A
Out[38]: 
array([[1, 2],
       [2, 3]])

In [39]: A_new = np.zeros(new_shape,dtype = A.dtype)

In [40]: A_new[0:A.shape[0],0:A.shape[1]] = A

In [41]: A_new
Out[41]: 
array([[1, 2, 0, 0],
       [2, 3, 0, 0],
       [0, 0, 0, 0]])

In MATLAB, you can use padarray -

A_new  = padarray(A,[1 2],'post')

Sample run -

>> A
A =
     1     2
     2     3
>> A_new = padarray(A,[1 2],'post')
A_new =
     1     2     0     0
     2     3     0     0
     0     0     0     0
2 of 3
5

Pure Python way achieve this:

row = 3
column = 4
A = [[1, 2],[2, 3]]

A_new = map(lambda x: x + ([0] * (column - len(x))), A + ([[0] * column] * (row - len(A))))

then A_new is [[1, 2, 0, 0], [2, 3, 0, 0], [0, 0, 0, 0]].

Good to know:

  • [x] * n will repeat x n-times
  • Lists can be concatenated using the + operator

Explanation:

  • map(function, list) will iterate each item in list pass it to function and replace that item with the return value
  • A + ([[0] * column] * (row - len(A))): A is being extended with the remaining "zeroed" lists
    • repeat the item in [0] by the column count
    • repeat that array by the remaining row count
  • ([0] * (column - len(x))): for each row item (x) add an list with the remaining count of columns using