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.
How do I declare an array in Python? - Stack Overflow
Python arrays
I need help with arrays
Are arrays and lists essentially the same?
Videos
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.
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 toarr[0]) appendoperation is 'for free' while some extra spaceinsertoperation 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:

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.