variable = []

Now variable refers to an empty list*.

Of course this is an assignment, not a declaration. There's no way to say in Python "this variable should never refer to anything other than a list", since Python is dynamically typed.


*The default built-in Python type is called a list, not an array. It is an ordered container of arbitrary length that can hold a heterogenous collection of objects (their types do not matter and can be freely mixed). This should not be confused with the array module, which offers a type closer to the C array type; the contents must be homogenous (all of the same type), but the length is still dynamic.

Answer from sepp2k on Stack Overflow
Top answer
1 of 16
427
variable = []

Now variable refers to an empty list*.

Of course this is an assignment, not a declaration. There's no way to say in Python "this variable should never refer to anything other than a list", since Python is dynamically typed.


*The default built-in Python type is called a list, not an array. It is an ordered container of arbitrary length that can hold a heterogenous collection of objects (their types do not matter and can be freely mixed). This should not be confused with the array module, which offers a type closer to the C array type; the contents must be homogenous (all of the same type), but the length is still dynamic.

2 of 16
196

This is surprisingly complex topic in Python.

Practical answer

Arrays are represented by class list (see reference and do not mix them with generators).

Check out usage examples:

# empty array
arr = [] 

# init with values (can contain mixed types)
arr = [1, "eels"]

# get item by index (can be negative to access end of array)
arr = [1, 2, 3, 4, 5, 6]
arr[0]  # 1
arr[-1] # 6

# get length
length = len(arr)

# supports append and insert
arr.append(8)
arr.insert(6, 7)

Theoretical answer

Under the hood Python's list is a wrapper for a real array which contains references to items. Also, underlying array is created with some extra space.

Consequences of this are:

  • random access is really cheap (arr[6653] is same to arr[0])
  • append operation is 'for free' while some extra space
  • insert operation is expensive

Check this awesome table of operations complexity.

Also, please see this picture, where I've tried to show most important differences between array, array of references and linked list:

🌐
GeeksforGeeks
geeksforgeeks.org › python › declaring-an-array-in-python
Declaring an Array in Python - GeeksforGeeks
July 10, 2025 - Declaring an array in Python means creating a structure to store multiple values, usually of the same type, in a single variable. For example, if we need to store five numbers like 10, 20, 30, 40, and 50, instead of using separate variables ...
🌐
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.
🌐
Sentry
sentry.io › sentry answers › python › declare an array in python
Declare an array in Python | Sentry
July 15, 2023 - from array import array my_int_array = array('i', [1, 2, 3, 4, 5]) # create an array of signed integers my_int_array.append(6) # will add 6 to the end of the array my_int_array.append('a') # will throw a TypeError: an integer is required (got type str) ... Tasty treats for web developers brought to you by Sentry. Get tips and tricks from Wes Bos and Scott Tolinski. SEE EPISODES ... David Y. — April 15, 2023 ... David Y. — March 15, 2023 · Change the order of columns in a Python Pandas DataFrame
🌐
Python
docs.python.org › 3 › library › array.html
array — Efficient arrays of numeric values
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.
🌐
AskPython
askpython.com › home › python array declaration: a comprehensive guide for beginners
Python Array Declaration: A Comprehensive Guide for Beginners - AskPython
April 3, 2023 - In this method, we use the array() function from the array module to create an array in Python. In Python, you can declare arrays using the Python Array Module, Python List as an Array, or Python NumPy Array.
🌐
NumPy
numpy.org › doc › stable › user › basics.creation.html
Array creation — NumPy v2.4 Manual
NumPy arrays can be defined using Python sequences such as lists and tuples. Lists and tuples are defined using [...] and (...), respectively.
🌐
Tutorialspoint
tutorialspoint.com › python › python_arrays.htm
Python - Arrays
Each element can be accessed via its index. For example, we can fetch an element at index 6 as 9. To create an array in Python, import the array module and use its array() function.
Find elsewhere
🌐
AskPython
askpython.com › home › 3 ways to initialize a python array
3 ways to initialize a Python Array - AskPython
January 16, 2024 - We have created an array — ‘arr’ and initalized it with 5 elements carrying a default value (0). ... Python NumPy module can be used to create arrays and manipulate the data in it efficiently.
🌐
Cython
cython.readthedocs.io › en › latest › src › tutorial › array.html
Working with Python arrays — Cython 3.3.0a0 documentation
To avoid having to use the array constructor from the Python module, it is possible to create a new array with the same type as a template, and preallocate a given number of elements. The array is initialized to zero when requested. ... from cython.cimports.cpython import array import array int_array_template = cython.declare(array.array, array.array('i', [])) cython.declare(newarray=array.array) # create an array with 3 elements with same type as template newarray = array.clone(int_array_template, 3, zero=False)
🌐
TestMu AI Community
community.testmu.ai › ask a question
How to declare an array in Python? - TestMu AI Community
June 28, 2024 - First, you need to import the array module (import array). Then, you can create an array with a specific data type like this: my_array = array.array(‘i’, [1, 2, 3, 4, 5]), where ‘i’ indicates the data type (integer in this case) · Another ...
🌐
FavTutor
favtutor.com › blogs › how-to-initialize-an-array-in-python
How to Initialize an Array in Python? (with Code) | FavTutor
January 27, 2021 - These elements allocate contiguous memory locations that allow easy modifications in data. In the python language, before using an array we need to declare a module named “array” using the keyword “import”.
🌐
CodingNomads
codingnomads.com › python-array-with-type
Python Array with Type
Python provides the ability to create a Python array with a specific type, and this lesson shows you how.
🌐
Finxter
blog.finxter.com › declare-an-array-python
How to declare an array in Python? – Be on the Right Side of Change
February 16, 2022 - You can use the Numpy module to declare arrays in Python. As a matter of fact, the Numpy module has been specifically designed to work with arrays.
🌐
Programiz
programiz.com › python-programming › array
Python Array of Numeric Values
In this tutorial, you’ll learn about Python array module, the difference between arrays and lists, and how and when to use them with the help of examples.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-initialize-empty-array-of-given-length
Python - Initialize empty array of given length - GeeksforGeeks
In this example, we are using Python List comprehension for 1D and 2D empty arrays. Using list comprehension like [[0] * 4 for i in range(3)] creates independent lists for each row.
Published   July 12, 2025
🌐
The Geek Stuff
thegeekstuff.com › 2013 › 08 › python-array
15 Python Array Examples – Declare, Append, Index, Remove, Count
August 12, 2013 - In the declaration above, ‘arrayIdentifierName’ is the name of array, ‘typecode’ lets python know the type of array and ‘Initializers’ are the values with which array is initialized.
🌐
Shiksha
shiksha.com › home › it & software › it & software articles › programming articles › how to use python array
How to use Python Array - Shiksha Online
October 27, 2023 - Arrays are fundamental data structures that are used to store the elements of the same data type at contiguous memory allocations. This article will briefly discuss what an array is in Python and how to use them in Python.
🌐
Studytonight
studytonight.com › python-howtos › how-to-declare-an-array-in-python
How to declare an array in Python - Studytonight
As mentioned earlier, there is no built-in support for arrays in Python, but we can use Python lists to create array-like structures, array1 = [0, 0, 0, 1, 2] array2 = ["cap", "bat", "rat"] Here, we declare an empty array.
🌐
Intellipaat
intellipaat.com › home › blog › python arrays – the complete guide
What is Python Arrays amd How to Declare Them (UPDATED)
October 14, 2025 - In Python, arrays are generally used to store multiple values of the same type in a single variable. The array module in Python allows you to create and initialize an array and for that, you first need to import it first. Now, let’s look at the example of declaring an array in Python.