Python Tuples : In this Unit…
Pre-requisite for this article : All about Python Tuples
Python Tuples are immutable objects. We all know this but how ?
Immutable objects are the objects whose content can not be modified. In Python, Tuples are said to be Immutable objects.
Consider the following code
tup = (10, 13, 12, 14, 15, 20)
Now, let’s try to modify the element in this tuple.
tup = (10, 13, 12, 14, 15, 20)
tup[2] = 100 # modifying third element to 100
print(tup)
O/P
TypeError: ‘tuple’ object does not support item assignment
Hence, upon running the above code, we got TypeError, this is due to Tuple’s Immutability Nature which will not allow us to modify any data in the existing tuple but this can be achieved in a simple way in Python Lists.
Only way to do this is via Tuple Slicing and Concatenation.
