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
๐ŸŒ
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.
๐ŸŒ
Python
docs.python.org โ€บ 3 โ€บ library โ€บ array.html
array โ€” Efficient arrays of numeric values
This module defines an object type which can compactly represent an array of basic values: characters, integers, floating-point numbers. Arrays are mutable sequence types and behave very much like lists, except that the type of objects stored ...
๐ŸŒ
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: 1 week ago
๐ŸŒ
New York University
physics.nyu.edu โ€บ pine โ€บ pymanual โ€บ html โ€บ chap3 โ€บ chap3_arrays.html
3. Strings, Lists, Arrays, and Dictionaries โ€” PyMan 0.9.31 documentation
The most import data structure for scientific computing in Python is the NumPy array. NumPy arrays are used to store lists of numerical data and to represent vectors, matrices, and even tensors. NumPy arrays are designed to handle large data sets efficiently and with a minimum of fuss.
๐ŸŒ
YouTube
youtube.com โ€บ the comparison channel
ARRAYS in Python - Start Here! - YouTube
So, what is an array? Well, it's a data structure that stores a collection of items, typically in a contiguous block of memory. This means that all items in ...
Published: December 10, 2022
Views: 53K
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ python arrays
r/learnpython on Reddit: Python arrays
March 3, 2025 -

I'm following roadmap.sh/python to learn python. I'm at the DSA section.

I understand the concept of arrays in DSA, but what I don't understand is how to represent them in Python.

Some tutorials I've seen use lists to represent arrays (even though arrays are homogeneous and lists are heterogeneous).

I've seen some other tutorials use the arrays module to create arrays like array.array('i') where the array has only integers. But I have never seen anybody use this module to represent arrays.

I've also seen some tutorials use numpy arrays. Which I don't understand their difference from the normal arrays module.

What should I use to represent arrays?

So far I've solved a couple of arrays exercises using Python lists.

Find elsewhere
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:

๐ŸŒ
Mimo
mimo.org โ€บ glossary โ€บ python โ€บ arrays
Python Arrays: Syntax, Usage, and Examples
Python arrays provide a structured way to store multiple values in a single variable. While Python doesnโ€™t have built-in arrays in the same way as some other languages, it supports them through modules like array and via more commonly used lists.
๐ŸŒ
YouTube
youtube.com โ€บ telusko
#26 Python Tutorial for Beginners | Array in Python - YouTube
Python Tutorial to learn Python programming with examples Complete Python Tutorial for Beginners Playlist : https://www.youtube.com/watch?v=hEgO047GxaQ&t=0s&
Published: July 18, 2018
Views: 549K
๐ŸŒ
Akamai
akamai.com โ€บ cloud โ€บ guides โ€บ python-arrays
Python Arrays: What They Are and How to Use Them | Linode Docs
June 17, 2022 - The main difference between lists and arrays is that arrays constrain the object type it can store. Lists do not give you a way to limit the types of objects they contain. When using an array, you can be sure that it only contains the type that was specified upon creation. A single Python list can simultaneously store integers, strings, and dictionaries.
๐ŸŒ
Princeton University
introcs.cs.princeton.edu โ€บ python โ€บ 14array
Arrays in Python
In its most basic form, an array supports four core operations: creation, indexed access, indexed assignment, and iteration. In this booksite, we use Python's built-in list data type for arrays because it supports these basic operations.
๐ŸŒ
Python Data Science Handbook
jakevdp.github.io โ€บ PythonDataScienceHandbook โ€บ 02.02-the-basics-of-numpy-arrays.html
The Basics of NumPy Arrays | Python Data Science Handbook
Data manipulation in Python is nearly synonymous with NumPy array manipulation: even newer tools like Pandas (Chapter 3) are built around the NumPy array. This section will present several examples of using NumPy array manipulation to access data and subarrays, and to split, reshape, and join ...
๐ŸŒ
Real Python
realpython.com โ€บ ref โ€บ glossary โ€บ array
array | Python Glossary โ€“ Real Python
In Python, an array is a data structure that holds a sequence of objects of the same data type.
๐ŸŒ
NumPy
numpy.org โ€บ doc โ€บ stable โ€บ reference โ€บ generated โ€บ numpy.array.html
numpy.array โ€” NumPy v2.5 Manual
Specify the memory layout of the array. If object is not an array, the newly created array will be in C order (row major) unless โ€˜Fโ€™ is specified, in which case it will be in Fortran order (column major).
๐ŸŒ
Readthedocs
pythontutorial-wdyds.readthedocs.io โ€บ en โ€บ latest โ€บ 3_Lists_Arrays โ€บ lists_arrays.html
4. Lists and Arrays โ€” A Python Tutorial for Data Scientists 2.0 documentation
While this was maybe interesting, real modern data is โ€œbigโ€, so we need to be able to deal with collections of data and not just one number at a time. Thankfully, this is where Python has a native list type and where weโ€™ll introduce the extremely useful numpy array, (numpy.ndarray) to handle many data points.
๐ŸŒ
DataCamp
datacamp.com โ€บ tutorial โ€บ python-arrays
Python Arrays: How to Create & Print Arrays using NumPy | DataCamp
August 8, 2024 - Pythonโ€™s array module provides basic functionality for creating compact, type-restricted arrays similar to those in languages like C. On the other hand, NumPy arrays offer advanced features such as support for multidimensional arrays, a vast library of mathematical functions, and performance optimizations through vectorization.
๐ŸŒ
The Knowledge Academy
theknowledgeacademy.com โ€บ blog โ€บ python-array
Python Arrays: Everything You Should Know
November 21, 2025 - A Python array stores same-type items in contiguous memory, and you can work with arrays using either Pythonโ€™s built-in array module or NumPy.
๐ŸŒ
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.
๐ŸŒ
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.