Array Vs List In Python
What would you say if someone asked you how Array differs from the List in python?
I got you! As a beginner, I faced this problem many times because by looking at these data structures you would not understand how they are different from each other as most of their functionality is the same. So now I had a problem which I need to fix by doing some research on the internet.
Information that I got over the internet that helped me to understand the difference between these datatypes:
an Array is a data type in Python also, meaning we have the array type and list type (the list type being more popular). Most people get to use arrays when they venture into Data Science and make use of libraries such as numpy. Arrays are the real workhorse of data structures for scientific and engineering applications. The most popular type of array used in Python is the numpy array.
Similarities between List & Array
- Both are used to store multiple values inside a single variable
- Both are ordered which means you can access elements inside a List/Array through their indexes. (In both data structures the index starts from zero and ends on n-1)
- Both data structures are represented by square brackets & both are dynamic in nature which means you can add and remove elements from a List/Array.
- Both can be sliced Which means you can extract a specific part of an Array/List.
Differences
The main difference between these two data types is the operation you can perform on them. Arrays are specially optimized for arithmetic computations so if you’re going to perform similar operations you should consider using an array instead of a list.
Get Rajat Singh’s stories in your inbox
Join Medium for free to get updates from this writer.
Also, lists are containers for elements having different data types but arrays are used as containers for elements of the same data type.
The example below is the result of dividing an array by a certain number and doing the same for a list. When we try the same operation (example: division) on a list, we get a TypeError because built-in python lists do not support the `__div__` protocol. It takes an extra step to perform this calculation on a list because then you’d have to loop over each item one after the other and save it to another list.
Stress!!
Making use of more robust array data types isn’t also without its cost implications. For example, to use numpy arrays you need to introduce a dependency in your project on the numpy library. You’d have to install the numpy package, import it and declare it while a list can be created on the fly.
While numpy provides a more robust array data type suited for numerical computation, Python also has a built-in array data type.
Before you go…
Thanks for reading!
If you enjoyed this article, please hold down the clap button 👏 to help others find it. The longer you hold it, the more claps you give!








