Difference between List and Array in Python
Last Updated :
15 Jul, 2025
In Python, lists and arrays are the data structures that are used to store multiple items. They both support the indexing of elements to access them, slicing, and iterating over the elements. In this article, we will see the difference between the two.
Operations Difference in Lists and Arrays
Accessing element is fast in Python Arrays because they are in a contiguous manner but insertion and deletion is quite expensive because all the elements are shifted from the position of inserting and deleting element linearly. Suppose the array is of 1000 length and we are inserting/deleting elements at 100 position then all the elements after the hundred position will get shifted due to which the operation becomes expensive.
Accessing an element in a Python List is the same as an Array because a List is actually a dynamic array . Inserting or deleting elements at the beginning or in the middle of a list can be less efficient because it may require shifting all subsequent elements, which is a linear-time operation in the worst case.
What are Lists?
A list in Python is an inbuilt collection of items that can contain elements of multiple data types, which may be either numeric, character logical values, etc. It is an ordered collection supporting negative indexing. A list can be created using [] containing data values. Contents of lists can be easily merged and copied using Python's inbuilt functions.
Example:
In this example, we are creating a list in Python. The first element of the list is an integer, the second a Python string, and the third is a list of characters.
Python
# creating a list containing elements
# belonging to different data types
sample_list = [1, "Yash", ['a', 'e']]
print(type(sample_list))
print(sample_list)
Output:
<class 'list'>
[1, 'Yash', ['a', 'e']]
What are Arrays?
An array is a vector containing homogeneous elements i.e. belonging to the same data type. Elements are allocated with contiguous memory locations. Typically the size of an array is fixed. Th e insertion and deletion costs are high as compared to the list however indexing is faster in the Arrays due to contiguous memory allocation. Arrays can be used by importing the array module.
Example:
In this example, we will create a Python array by using the array() function of the array module and see its type using the type() function.
Python
# importing "array" for array creations
import array as arr
# creating an array with integer type
a = arr.array('i', [1, 2, 3])
print(type(a))
for i in a:
print(i, end=" ")
Output:
<class 'array.array'>
1 2 3
Difference Between List and Array in Python
The following table shows the differences between List and Array in Python:
List | Array |
---|
Can consist of elements belonging to different data types | Only consists of elements belonging to the same data type |
No need to explicitly import a module for the declaration | Need to explicitly import the array module for declaration |
Cannot directly handle arithmetic operations | Can directly handle arithmetic operations |
Preferred for a shorter sequence of data items | Preferred for a longer sequence of data items |
Greater flexibility allows easy modification (addition, deletion) of data | Less flexibility since addition, and deletion has to be done element-wise |
The entire list can be printed without any explicit looping | A loop has to be formed to print or access the components of the array |
Consume larger memory for easy addition of elements | Comparatively more compact in memory size |
Nested lists can be of variable size | Nested arrays has to be of same size. |
Can perform direct operations using functions like: count() - for counting a particular element in the list sort() - sort the complete list max() - gives maximum of the list min() - gives minimum of the list sum() - gives sum of all the elements in list for integer list index() - gives first index of the element specified append() - adds the element to the end of the list remove() - removes the element specified No need to import anything to use these functions. and many more... | Need to import proper modules to perform these operations. |
Example: my_list = [1, 2, 3, 4] | Example: import array arr = array.array('i', [1, 2, 3]) |
What is the Difference Between ArrayList and Set in Python?
Python doesn't have an ArrayList
as it is a concept from Java. The closest equivalent in Python is a list
. Here's how it compares to a set
:
- List:
- Ordered collection which means it maintains the order of elements as they were added.
- Can contain duplicate elements.
- Example:
- Set:
- An unordered collection of unique elements. It automatically removes any duplicate entries.
- Because it is unordered, it does not support operations that depend on sequence (like indexing).
- Example:
my_list = [1, 2, 2, 3]
my_set = {1, 2, 2, 3} # Output will be {1, 2, 3}
What is the Difference Between Array and List in Python Stack Overflow?
This refers to common questions asked on Stack Overflow about the difference between arrays and lists in Python, which typically highlight:
- Arrays are best for numeric data and require the specification of a data type.
- Lists are more general-purpose containers that are more flexible but less memory efficient for large numeric data sets.
What is the Difference Between List, Array, and Dictionary in Python?
- List: An ordered sequence of elements that can contain items of different types. Lists are versatile for handling a sequence of elements that need to be ordered and may need to be changed.
- Array: As provided by Python's
array
module, used primarily for storing homogeneous numeric data in a compact and efficient manner. - Dictionary: An unordered collection of key-value pairs. Dictionaries are optimized for retrieving data where each element is accessed by a unique key. This is ideal for large datasets where fast lookup, insertion, and deletion of elements is required.
What is the Difference Between Remove and Pop?
- Used to remove the first occurrence of a specific value from a list.
- Does not return the removed element.
- Raises a
ValueError
if the specified value is not found. - Syntax:
my_list = [1, 2, 3, 2]
my_list.remove(2) # Removes the first '2'
- Remove:
- Pop:
- Removes an element at a specific index and returns it.
- If no index is specified,
pop()
removes and returns the last item in the list. - Raises an
IndexError
if the specified index is out of range. - Syntax:
my_list = [1, 2, 3]
removed_element = my_list.pop(1) # Removes and returns '2'
These operations allow for specific element manipulation in lists, with pop()
often being useful when implementing data structures like stacks and queues.
Similar Reads
Python Tutorial - Learn Python Programming Language Python is one of the most popular programming languages. Itâs simple to use, packed with features and supported by a wide range of libraries and frameworks. Its clean syntax makes it beginner-friendly. It'sA high-level language, used in web development, data science, automation, AI and more.Known fo
10 min read
Python Interview Questions and Answers Python is the most used language in top companies such as Intel, IBM, NASA, Pixar, Netflix, Facebook, JP Morgan Chase, Spotify and many more because of its simplicity and powerful libraries. To crack their Online Assessment and Interview Rounds as a Python developer, we need to master important Pyth
15+ min read
Python OOPs Concepts Object Oriented Programming is a fundamental concept in Python, empowering developers to build modular, maintainable, and scalable applications. OOPs is a way of organizing code that uses objects and classes to represent real-world entities and their behavior. In OOPs, object has attributes thing th
11 min read
Python Projects - Beginner to Advanced Python is one of the most popular programming languages due to its simplicity, versatility, and supportive community. Whether youâre a beginner eager to learn the basics or an experienced programmer looking to challenge your skills, there are countless Python projects to help you grow.Hereâs a list
10 min read
Python Exercise with Practice Questions and Solutions Python Exercise for Beginner: Practice makes perfect in everything, and this is especially true when learning Python. If you're a beginner, regularly practicing Python exercises will build your confidence and sharpen your skills. To help you improve, try these Python exercises with solutions to test
9 min read
Python Programs Practice with Python program examples is always a good choice to scale up your logical understanding and programming skills and this article will provide you with the best sets of Python code examples.The below Python section contains a wide collection of Python programming examples. These Python co
11 min read
Python Introduction Python was created by Guido van Rossum in 1991 and further developed by the Python Software Foundation. It was designed with focus on code readability and its syntax allows us to express concepts in fewer lines of code.Key Features of PythonPythonâs simple and readable syntax makes it beginner-frien
3 min read
Python Data Types Python Data types are the classification or categorization of data items. It represents the kind of value that tells what operations can be performed on a particular data. Since everything is an object in Python programming, Python data types are classes and variables are instances (objects) of thes
9 min read
Input and Output in Python Understanding input and output operations is fundamental to Python programming. With the print() function, we can display output in various formats, while the input() function enables interaction with users by gathering input during program execution. Taking input in PythonPython's input() function
7 min read
Enumerate() in Python enumerate() function adds a counter to each item in a list or other iterable. It turns the iterable into something we can loop through, where each item comes with its number (starting from 0 by default). We can also turn it into a list of (number, item) pairs using list().Let's look at a simple exam
3 min read