Detailed difference between List VS Tuple

Python List Vs Tuple

In this tutorial, we will learn the important difference between the list and tuples and how both are playing a significant role in Python.

Lists and Tuples are used to store one or more Python objects or data-types sequentially. Both can store any data such as integer, float, string, and dictionary. Lists and Tuples are similar in most factors but here we will describe the main difference between them.

Let’s discuss the main differences in the following points.



Loaded: 12.32%


Representation Differences

The representation of the Lists and tuple is marginally different. List are commonly enclosed with the square bracket [], and elements are comma-separated element. Tuples are enclosed with parenthesis (), and elements are separated by the comma. The parenthesis is optional to use, and these types of tuples are called tuple packing.

Consider the following example.

> list1 = ['JavaTpoint', 1, 2, 54.30, {'Name: ''Peter'}]  
> print(type(list))  
> tuple1 = ('JavaTpoint',5,8,31.9,[1,2,3])  
> print(type(tuple1))  
> Output:
<class 'list'>
<class 'tuple'>

In the above program, we defined a list1 variable which holds a list of different data type from index 0 to 4. We defined another variable tuple1, which holds a tuple of different data types. It is enclosed by the ().

Mutable Lists and Immutable Tuples

It is the most important difference between list and tuple whereas lists are mutable, and tuples are immutable. The lists are mutable which means the Python object can be modified after creation, whereas tuples can’t be modified after creation. Consider the given an example.

a = ["Peter","Joseph","Mathew","Ricky"]  

['Peter', 'Joseph', 'Mathew', 'Ricky']
Now we are changing 0th index element "Peter" to "Samson".

a[0] = "Samson"  

['Samson', 'Joseph', 'Mathew', 'Ricky']
Now we create a tuple and do the same thing.

a = (10,20,"JavaTpoint",30,40)  

(10, 20, 'JavaTpoint', 30, 40)

a[0] = 50  

TypeError                                 Traceback (most recent call last)
<ipython-input-5-52b2981fae12> in <module>
----> 1 a[0] = 50

TypeError: 'tuple' object does not support item assignment


The tuples are easy to debug in a big project because of its immutability. If we have a small project or less number of data, then lists play an effective role. Let’s consider the following example:

a = [6,9,4,3,7,0,1]  
# Copying address of a in b  
b = a  
a[3] = "JavaToint"  


[6, 9, 4, 'JavaToint', 7, 0, 1]

In the above code, we did b = a ; here we are not copying the list object from b to a. The b referred to the address of the list a . It means if we make the change in the b then that will reflect the same as in list a, and it makes debugging easy. But it is hard for the significant project where Python objects may have multiple references.

It will be very complicated to track those changes in lists but immutable object tuple can’t change after created.

So tuples are 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

    doc’,‘eq’,‘format’, ‘get’,‘getattribute’,’_getitem’ ‘gt’,‘hash’,‘iadd’,‘imul’,‘init’,‘init_subclass’‘iter’,‘le’,‘len’,‘lt’,‘mul’, ‘ne’,‘new’,
    reduce’, ‘reduce_ex’,‘repr’,‘reversed’,‘rmul’,‘setattr’,‘setitem’,‘sizeof’,‘str’,‘subclasshook’,

  • Tuple Functions



Memory Efficient

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 for the huge amount of data.
Tuple = (1,2,3,4,5,6,7,8,9,0,5485,87525,955,3343,53234,6423,623456,234535)
List = [1,2,3,4,5,6,7,8,9,0,78,34,43,32,43,55,54,212,642,533,43434,54532 ]
print(‘Tuple size =’, Tuple.sizeof()) # Tuple size = 52
print(‘List size =’, List.sizeof())


Tuple size = 168
List size = 216


  • In Some cases, lists might seem more useful than tuples. But tuples are important data structures of the Python. Tuples are commonly used for unchangeable data or we can say that the data will be “write- protected” in the tuples. Tuples sends the indication to the Python interpreter the data should not change in the future.
  • We can use tuple the same as a dictionary without using keys to store the data. For example-

list1 = [(101, "Mike", 24),(102, 'Hussey', 26),(103, 'David', 27),(104, 'Warner', 29)]
Tuples can use for the dictionary keys because these are hashable and immutable whereas lists can’t use a keys in dictionary.

dict = {(“Mike”,22):24000} #valid dictionary
dict = {[“Peter”,26]:25000} #Invalid dictionary