CBSE Class 11 : Python | Tuples 6

Changing a Tuple

Unlike lists, tuples are immutable.
This means that elements of a tuple cannot be changed once it has been assigned. But, if the element is itself a mutable data type like list, its nested items can be changed.

We can assign a tuple to different values (reassignment).
n=(0,1,2,3,4,5,6,7,8,9,10)
print(n)
output:
(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

n[1]=10
#error will get generated as tuple elements cannot be changed
print(n)

 

#but list within a tuple can be changed
n = (4, 2, 3, [6, 5])
print(n)
output:
(4, 2, 3, [6, 5])

n[3][0]=10
print(n)
Output:
(4, 2, 3, [10, 5])
n[3][1]=100
print(n)
Output:
(4, 2, 3, [10, 100])