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
Arrays are used to store multiple values in one single variable.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-arrays
Python Arrays - GeeksforGeeks
Explanation: parameter 'i' is the ... their mapped C types and minimum memory requirements: Array can be created by importing an array module....
Published: September 19, 2026
People also ask

How do I initialize an array in Python with a size?
For a general one-dimensional sequence, use a list such as [None] * size or [0] * size. For a NumPy array, pass a length or shape tuple to a creation function such as np.zeros() or np.full().
🌐
askpython.com
askpython.com › python › array › initialize-a-python-array
3 Ways to Initialize an Array in Python - AskPython
Can I use Python’s array module for string or object data types?

No, the array module is designed to hold only basic data types like integers, floats, and similar. It does not support strings or objects. For collections of these types, Python’s list or other data structures like tuples or dictionaries are more appropriate.

🌐
datacamp.com
datacamp.com › home › tutorials › python › python arrays
Python Arrays: How to Create & Print Arrays using NumPy | DataCamp
What are the main differences between Python’s array module and NumPy arrays?

The main differences lie in capabilities and use cases. 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. NumPy is generally preferred for numerical and scientific computing.

🌐
datacamp.com
datacamp.com › home › tutorials › python › python arrays
Python Arrays: How to Create & Print Arrays using NumPy | DataCamp
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:

🌐
Pp4rs
pp4rs.github.io › pp4rs-python › notebooks › numpy › 01-create_array.html
Numpy Basics - Creating Arrays — Python for Economics and Business Research
In this notebook we focus on creating arrays, either by manually inputting the data ourselves, or using some built-in functionality to create an array with certain structures. In a later notebook we discuss how to import an array from an existing file on our machine. Since Python 3.3, Python has a built in array module that allows us to create a dense array where all elements are of a uniform type:
🌐
Python Guides
pythonguides.com › create-arrays-in-python
How To Create Arrays In Python?
July 27, 2026 - Create one with square brackets, add mixed types, and grow it with append() or extend(). Use NumPy for fast numeric calculations, multi-dimensional grids, or built-in functions like sums and averages. A plain list is fine for simple records like names. Yes, a Python list can hold strings, numbers, and booleans together. NumPy arrays, on the other hand, expect one consistent dtype across all elements.
🌐
Sentry
sentry.io › sentry answers › python › declare an array in python
Declare and Initialize an Array (List) in Python | Sentry
October 1, 2026 - 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. — September 23, 2026 ... David Y. — July 3, 2026 ... David Y. — September 10, 2026 · Resolve Python ImportError: No module named ...
Find elsewhere
🌐
W3Schools
w3schools.com › python › numpy › numpy_creating_arrays.asp
NumPy Creating Arrays
NumPy is used to work with arrays. The array object in NumPy is called ndarray.
🌐
DataCamp
datacamp.com › home › tutorials › python › python arrays
Python Arrays: How to Create & Print Arrays using NumPy | DataCamp
August 8, 2024 - Python’s standard library includes an array module, which allows for the creation of compact, type-restricted arrays similar to those in more statically-typed languages.
🌐
AskPython
askpython.com › python › array › initialize-a-python-array
3 Ways to Initialize an Array in Python - AskPython
1 week ago - Use a Python list for general values, array.array for compact typed values, or NumPy when you need shaped numerical data.
🌐
Guru99
guru99.com › home › python › python array – define, create
Python Array – Define, Create
July 10, 2026 - It is used to store collections of data. In Python programming, an arrays are handled by the “array” module. If you create arrays using the array module, elements of the array must be of the same numeric type.
🌐
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.
🌐
freeCodeCamp
freecodecamp.org › news › python-array-tutorial-define-index-methods
Python Array Tutorial – Define, Index, Methods
January 31, 2022 - Inside square brackets you mention the elements that would be stored in the array, with each element being separated by a comma. You can also create an empty array by just writing variable_name = array(typecode) alone, without any elements. Below is a typecode table, with the different typecodes that can be used with the different data types when defining Python arrays:
🌐
Kitchin Research Group
kitchingroup.cheme.cmu.edu › blog › 2013 › 02 › 26 › Creating-arrays-in-python
Creating arrays in python - Kitchin Research Group
February 26, 2013 - The numpy.hsplit command splits an array “horizontally”. The best way to think about it is that the “splits” move horizontally across the array. In other words, you draw a vertical split, move over horizontally, draw another vertical split, etc…
🌐
NumPy
numpy.org › doc › stable › user › basics.creation.html
Array creation — NumPy v2.5 Manual
You can use these methods to create ndarrays or Structured arrays. This document will cover general methods for ndarray creation. NumPy arrays can be defined using Python sequences such as lists and tuples. Lists and tuples are defined using [...] and (...), respectively.
🌐
Codementor
codementor.io › blog › how to create an array in python and other things you need to know about python array
How to Create An Array in Python and other things you need to know about Python Array
July 1, 2021 - Arrays are a powerful and useful module. In Python, there are two ways you can create an array: using the Python Standard Library or the NymPy package.
🌐
Mimo
mimo.org › tutorials › python › how-to-create-an-array-in-python
How to Create an Array in Python
Create arrays in Python with lists, array.array, or NumPy, based on whether you need flexibility, fixed numeric types, or fast math.
🌐
Programiz
programiz.com › python-programming › array
Python Array of Numeric Values
March 26, 2024 - Note: When people say arrays in Python, more often than not, they are talking about Python lists. If that's the case, visit the Python list tutorial. To create an array of numeric values, we need to import the array module.
🌐
Tutorialspoint
tutorialspoint.com › python › python_arrays.htm
Python - Arrays
To create an array in Python, import the array module and use its array() function.
🌐
Reddit
reddit.com › r/learnpython › is it possible to create an array in python?
r/learnpython on Reddit: Is it possible to create an array in python?
May 2, 2024 -

I started using python a few days ago ( I already studied C before ) and I noticed that python uses Linked Lists by default, is there any way to use arrays and use less memory?

Top answer
1 of 6
33
I noticed that python uses Linked Lists by default It does not. Python's list type is a dynamically growing array, similar to vectors in C++, ArrayLists in Java, Lists in C# or arrays in Ruby, Perl, PHP or JavaScript.
2 of 6
19
Like others have said, Python uses Dynamic Arrays, not Linked Lists for the list implementation. If you need a more efficient storage container for numeric data, consider the array module. If you need something more fully featured, consider pandas.DataFrame . There's also numpy Arrays . Both Pandas and Numpy use compiled C under the hood for performance and memory concerns. However, I want to warn you that premature optimization is a serious problem for new programmers, especially those who come to Python from other languages and expect that you have to optimize everything to hell and back just to get acceptable performance. You can do a fair bit of processing in pure python before you need to rely on something like the above libraries to speed stuff up. You should only consider optimizing code once you've reached a point where it is definitively too slow/memory hungry. And even then there's often a lot you can do to cut down on memory usage or speed things up without resorting to bringing in external dependencies when you actually understand how Python works, and how to write performant data structures and algorithms. Very often the problem is that people are using bad data structures or algorithms, rather than the raw performance/memory use of Python itself. That said, there are certainly cases where you do simply need libraries like above. It all comes down to exactly what you're doing and how you're trying to do it.
🌐
Replit
replit.com › home › discover › how to create an array in python
How to create an array in Python | Replit
April 14, 2026 - Learn how to create arrays in Python. This guide covers different methods, tips, real-world applications, and how to debug common errors.