What is the Difference Between List and Tuple in Python?
Learn via video course

Overview
In Python, List is a type of container in data structures, which is used to store multiple data types at the same time. Lists are a useful tool for preserving a sequence of data and further iterating over it. While, a Tuple is an immutable collection of Python objects separated by commas i.e a tuple can’t be changed or modified after its creation.
Scope
This article tells difference between the list and tuple in python.
In this article we will learn differences in list and tuple.
In this article we will learn examples of list and tuple.
In this article we will learn Mutability of list and tuple.
In this article we will learn functions of list and tuple.
In this article we will learn efficiency of list and tuple.
Takeaways
The key difference between the tuples and lists is that while the tuples are immutable objects the lists are mutable.
Both lists and tuples can store any data such as integer, float, string, and dictionary. Lists and Tuples are similar in most factors but in this article we will describe the main difference between them.
list vs tuple in python
S. No | List | Tuple |
---|---|---|
1 | Lists are mutable. | Tuples are immutable. |
2 | Iteration in lists is time consuming. | Iteration in tuples is faster |
3 | Lists are better for insertion and deletion operations | Tuples are appropriate for accessing the elements |
4 | Lists consume more memory | Tuples consume lesser memory |
5 | Lists have several built-in methods | Tuples have comparatively lesser built-in methods. |
6 | Lists are more prone to unexpected errors | Tuples operations are safe and chances of error are very less |
7 | Creating a list is slower because two memory blocks need to be accessed. | Creating a tuple is faster than creating a list. |
Examples
Mutability
The major difference between list and tuple whereas lists are mutable, and tuples are immutable. The lists are mutable means that the Python object(list) can be modified after creation, whereas tuples can't be modified after creation.
Let us understand this with the help of following example, by creating a list named fruits:
Output:
Now we are changing the first fruit by accessing the 0th index in the fruits list.
Output:
Let's now perform the same operation on a tuple:
Output:
Now we are changing the first fruit by accessing the 0th index in the fruits tuple.
Output:
We encounter an error while changing the first element (at 0th index) of the tuple because of immutability. As tuples does not support item assignment.
Debugging
The tuples are easy to debug in a large scale project because of its immutability. If we have a small scale project having less data, then lists are a good choice for effective programming. Let us understand this with the help of following example,
Output:
In the above program, we did b = a, here this line of code does not mean we are copying the list object from a to a. This b now refers to the address of the list a which implies if we make any change in the list a then that will reflect the same as in list b, and thus debugging becomes easy. But it is hard in case where Python objects may have multiple references, it will be very complicated to track those changes in lists but immutable object tuple can't be changed once created thus making tuples easy to debug.
Functions Support
The tuples support less operation than the list. The inbuilt dir(object) is used to get all the supported functions for the list and tuple.
List Functions
Output:
Tuple Functions
Output:
Efficiency
The tuples are more memory efficient than the list because tuple has less built-in operations. Lists are suitable for the fewer elements whereas tuples are a bit faster than the list when dealing with huge amount of data.
Output:
In the above program, despite the tuple A is having more number of characters as compared to the list B, list is occupying a larger size in computer's memory
Conclusion
- The literal syntax of tuples is shown by parentheses () whereas the literal syntax of lists is shown by square brackets [] .
- Lists and Tuples are data structures in python and are used to store one or more Python objects or data-types sequentially.
- Tuples can used as keys in a dictionary in python because these are hashable and immutable whereas lists can't be used as keys in dictionary.
- Tuples are used for unchangeable data that means data will be write- protected in tuples. Tuples sends an indication to the Python interpreter that the data should not change in the future.