You can use:

>>> lst = [None] * 5
>>> lst
[None, None, None, None, None]
Answer from samplebias on Stack Overflow
๐ŸŒ
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
True: you didnโ€™t find any contradictions; this behavior is standard in the Python library and most other collections libraries Iโ€™ve worked with ยท False: a kind of soft error indicator for an empty input ... raise an exception: raising exceptions is effectively an output value - just one that gets handled differently from normal program flow ... Itโ€™s easy enough to modify both to get true: just return True if the collection is empty right off the bat. ... RelatedHow do I initialize an array with a specific size in Python (like Roblox Luau's table.create (size, value) or LuaJIT's table.new (size, value) for example)?
๐ŸŒ
AskPython
askpython.com โ€บ home โ€บ 3 ways to initialize a python array
3 ways to initialize a Python Array - AskPython
January 16, 2024 - Python NumPy module can be used to create arrays and manipulate the data in it efficiently. The numpy.empty() function creates an array of a specified size with a default value = โ€˜Noneโ€™.
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
python - initialize a numpy array - Stack Overflow
Is there way to initialize a numpy array of a shape and add to it? I will explain what I need with a list example. If I want to create a list of objects generated in a loop, I can do: a = [] for i... More on stackoverflow.com
๐ŸŒ stackoverflow.com
Creating an array who size and values depend on another array's values being put through a function
Since you mention arrays and arange, I presume you're using Numpy. The way to create one array by applying a function to each element from another array is by using vectorize . More on reddit.com
๐ŸŒ r/learnpython
6
18
May 21, 2022
learning to declare and initialize arrays in a single line of code
okay i like LINQ. Like... a lot. To a problematic degree. But this is a fucking war crime. Bro woke up and didn't choose violence. They chose genocide. More on reddit.com
๐ŸŒ r/programminghumor
51
153
December 30, 2024
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-initialize-empty-array-of-given-length
Python - Initialize empty array of given length - GeeksforGeeks
# initialize the spaces with 0โ€™s with # the help of list comprehensions a = [0 for x in range(10)] print(a) b = [[0] * 4 for i in range(3)] print(b) ... In this example, we are using a Python loop for 1D and 2D empty arrays. ... In this method, we are using the Numpy module to generate an empty matrix of 1D and 2D sizes using np.empty().
Published ย  July 12, 2025
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ python_arrays.asp
Python Arrays
Note: Python does not have built-in support for Arrays, but Python Lists can be used instead. Note: This page shows you how to use LISTS as ARRAYS, however, to work with arrays in Python you will have to import a library, like the NumPy library.
๐ŸŒ
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โ€.
๐ŸŒ
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 - This article explains how to initialize a list of any size (number of elements) with specific values in Python. ... See the following article about initializing a NumPy array (numpy.ndarray).
Find elsewhere
๐ŸŒ
Java2Blog
java2blog.com โ€บ home โ€บ python โ€บ python array โ€บ how to initialize array in python
How to initialize array in Python - Java2Blog
November 20, 2020 - here, empty() method of numpy is used to create a numpy array of given size with default value None. ... Thatโ€™s all about how to initialize array in Python.
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ array.html
array โ€” Efficient arrays of numeric values
The actual size can be accessed through the array.itemsize attribute. ... A string with all available type codes. ... 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.
๐ŸŒ
Python Guides
pythonguides.com โ€บ initialize-an-array-in-python
How To Initialize An Array In Python?
March 19, 2025 - Learn how to initialize arrays in Python using methods like list comprehensions, NumPy's functions, and array modules. Step-by-step examples for various sizes.
๐ŸŒ
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.
๐ŸŒ
Quora
quora.com โ€บ How-do-I-create-an-array-of-a-specific-size-in-Python
How to create an array of a specific size in Python - Quora
Answer (1 of 3): (1) In Python, you donโ€™t typically work with arrays, but with lists. There are libraries to work with arrays, but you only use them for certain specialized purposes. Such as when you need matrix multiplication or some other advanced math, and want to do it quickly.
๐ŸŒ
Finxter
blog.finxter.com โ€บ home โ€บ learn python blog โ€บ 5 best ways to create a numpy array of size n in python
5 Best Ways to Create a NumPy Array of Size N in Python - Be on the Right Side of Change
February 20, 2024 - By calling np.ones(n), we quickly get an array of ones, with n defining the size. This approach is as straightforward as the first, showcasing the ease of initializing arrays in NumPy.
๐ŸŒ
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 - To initialize a list of size n in Python, you can use multiplication syntax or a range() statement. On Career Karma, learn how to initialize empty lists of custom sizes.
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ gloss_python_array_length.asp
Python Array Length
Python Examples Python Compiler ... Plan Python Interview Q&A Python Bootcamp Python Training ... Use the len() method to return the length of an array (the number of elements in an array)....
๐ŸŒ
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.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ declaring-an-array-in-python
Declaring an Array in Python - GeeksforGeeks
July 10, 2025 - Explanation: [] creates a list (array-like) in Python. Elements are accessed using a[i] and modified with a[i] = value.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ creating an array who size and values depend on another array's values being put through a function
r/learnpython on Reddit: Creating an array who size and values depend on another array's values being put through a function
May 21, 2022 -

Hi all,

I'm trying to create an 2 arrays. The 2nd array is the one I'm having trouble with. It needs to have a size based on a user inputted length.

These are my steps:

  1. I ask the user to input a start number and an end number.

  2. I create the first array using arange(first, last, 1)

  3. Each of the values in between first and last go through as the single input to another function.

  4. For the second array, each value in the array is the return values. So this gives 2 arrays of the same length that line up.

I don't know how to write step 3. I imagine it may even include a for loop. Something like

1st_array = (first, last, 1) difference = last - first 2nd_array = zeros(int(difference) for i in range(first, last) add value to 2nd array(function(1st array value 1), function(1st array value 2, .... function(1st array value n)

How could I do this?