Python Tutorial

Changing and Deleting Tuple Item Values

How to Change or Delete Tuple Item Values in Python?

Tuples are immutable, therefore you can't remove or change items from them. However, you may use the same workaround we used to add and change tuple items. 

Example:

Convert the tuple into a list, remove "cranberry", and convert it back into a tuple:

thist_uple = ("c", "b", "a")

y = list(this_tuple)

y.remove("c")

this_tuple = tuple(y)

Output:

('b', 'a')

Example:

The del keyword can delete the tuple completely:

this_tuple = ("c", "b", "a")

del this_tuple

print(this_tuple) #this will raise an error because the tuple no longer exists

Did you find this article helpful?