Mutating the Immutable!
We'll cover the following...
This might seem trivial if you know how references work in Python.
Press + to interact
>>> some_tuple = ("A", "tuple", "with", "values")>>> another_tuple = ([1, 2], [3, 4], [5, 6])>>> some_tuple[2] = "change this"TypeError: 'tuple' object does not support item assignment>>> another_tuple[2].append(1000) #This throws no error>>> another_tuple([1, 2], [3, 4], [5, 6, 1000])>>> another_tuple[2] += [99, 999]TypeError: 'tuple' object does not support item assignment>>> another_tuple([1, 2], [3, 4], [5, 6, 1000, 99, 999])
Let’s try these in the terminal below.
Explanatio ...
...