Open In App

Are Tuples Immutable in Python?

Last Updated : 03 Dec, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Yes, tuples are immutable in Python. This means that once a tuple is created its elements cannot be changed, added or removed. The immutability of tuples makes them a fixed, unchangeable collection of items. This property distinguishes tuples from lists, which are mutable and allow for modifications after creation.

Example: Attempting to Modify a Tuple

Let’s see an example where we attempt to modify a tuple:

Python
# Creating a tuple
tup = (1, 2, 3, 4)


 # Trying to change the third element
tup[2] = 99  

Output
Error: 'tuple' object does not support item assignment

As you can see, attempting to modify an element in a tuple results in a TypeError, which confirms that tuples are immutable.


Next Article
Article Tags :
Practice Tags :

Similar Reads