Use with AIvariable = []

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
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ array.html
array โ€” Efficient arrays of numeric values โ€” Python 3.15.2 documentation
3 weeks ago - This module defines an object type which can compactly represent an array of basic values: characters, integers, floating-point numbers, complex numbers. Arrays are mutable sequence types and behave very much like lists, except that the type ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-arrays
Python Arrays - GeeksforGeeks
Python provides multiple ways to work with linear data structures, which store elements sequentially. Although Python does not have a built-in array type like some other languages, similar functionality can be achieved using:
Published: September 19, 2026
๐ŸŒ
W3Schools
w3schools.com โ€บ python โ€บ ref_module_array.asp
Python array Module
The array module provides compact arrays of basic values (like integers and floats).
๐ŸŒ
Real Python
realpython.com โ€บ ref โ€บ stdlib โ€บ array
array | Python Standard Library โ€“ Real Python
The Python array module provides an efficient data structure for creating arrays of values (often numbers), which are stored more compactly than in standard lists.
๐ŸŒ
Educative
educative.io โ€บ answers โ€บ what-is-an-arrayarray-in-python
What is an array.array() in Python?
The function array.array() initializes an array with a typecode and initializer that must be a list, a bytes object, or an iterable.
๐ŸŒ
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.
๐ŸŒ
Mimo
mimo.org โ€บ glossary โ€บ python โ€บ arrays
Python Arrays: Syntax, Usage, and Examples
Start your coding journey with Python. Learn basics, data types, control flow, and more ... To create an array in Python, you can use either the built-in list type or the array module.
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ python-array-tutorial-define-index-methods
Python Array Tutorial โ€“ Define, Index, Methods
January 31, 2022 - Specifically, they are an ordered collection of elements with every value being of the same data type. That is the most important thing to remember about Python arrays - the fact that they can only hold a sequence of multiple items that are of the same type.
Find elsewhere
Top answer
1 of 16
427
Use with AIvariable = []

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:

Use with AI# 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:

๐ŸŒ
Programiz
programiz.com โ€บ python-programming โ€บ array
Python Array of Numeric Values
March 26, 2024 - If that's the case, visit the Python list tutorial. To create an array of numeric values, we need to import the array module.
๐ŸŒ
w3resource
w3resource.com โ€บ python โ€บ library โ€บ python_array_module.php
Python: array module - w3resource
April 20, 2026 - Python: array - This module defines an object type which can compactly represent an array of basic values: characters, integers, floating point numbers and methods with examples - w3resource
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ array-python-set-1-introduction-functions
Array Module in Python - GeeksforGeeks
August 2, 2025 - The array() function from Python's array module creates an array with elements of a specified data type.
๐ŸŒ
Simplilearn
simplilearn.com โ€บ home โ€บ resources โ€บ software development โ€บ your ultimate python tutorial for beginners โ€บ everything you need to know about python arrays
Everything You Need to Know about Python Arrays
June 14, 2024 - What is an array & why use array in Python? As creating an array means importing it to Python, learn the basic array operations, accessing array elements, & more.
๐ŸŒ
Real Python
realpython.com โ€บ python-array
Python's Array: Working With Numeric Data Efficiently โ€“ Real Python
May 13, 2026 - Instead of arrays, you typically use lists, which are slightly different and more flexible than classic arrays. That said, Python ships with the lesser-known array module in its standard library, providing a specialized sequence type that can help you process binary data.
๐ŸŒ
Python Geeks
pythongeeks.org โ€บ python geeks โ€บ learn python โ€บ python array module
Python Array Module - Python Geeks
September 22, 2021 - The array module is an extremely useful module for creating and maintaining arrays. These arrays are similar to the arrays in the C language. This article explains how to create arrays and several other useful methods to make working with arrays easier. This is a Python built-in module and comes ready to use in the Python Standard Library.
๐ŸŒ
Code Institute
codeinstitute.net โ€บ blog โ€บ python โ€บ python arrays
Python Arrays : A Guide - Code Institute Global
April 24, 2023 - While a list can contain items of many data types, an array can only store elements of a single data type. So, although the list can hold heterogeneous data values, an array keeps homogeneous data values. Since the Python languageโ€™s list data structure is built-in, no module or package must be imported before using it.
๐ŸŒ
Internshala
trainings.internshala.com โ€บ home โ€บ programming โ€บ python โ€บ what is python arrays?
Python Array: Types , Uses, Differences, & More
April 20, 2026 - Python Array allows us to store multiple elements of the same data type in an orderly collection. These can be any valid Python variable types, such as integers, strings, booleans, and more.
๐ŸŒ
WsCube Tech
wscubetech.com โ€บ resources โ€บ python โ€บ arrays
Arrays in Python: Types, Syntax and Examples
August 6, 2026 - Master arrays in Python with easy examples. Learn types of arrays in Python, array methods, element access, insertion, common array operations & more. Read now.
๐ŸŒ
Tutorialspoint
tutorialspoint.com โ€บ python โ€บ python_arrays.htm
Python - Arrays
To create an array in Python, import the array module and use its array() function.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ declaring-an-array-in-python
Declaring an Array in Python - GeeksforGeeks
July 10, 2025 - Explanation: array() from the array module creates a typed array in Python. 'i' denotes integer type.