Junior — Middle
Is it possible to modify the contents of a tuple after its creation?
sobes.tech AI
Answer from AI
In Python, a tuple is an immutable data type, meaning that once it is created, its contents cannot be changed directly. However, if a tuple contains mutable objects, such as lists, the contents of those objects can be modified.
Example:
t = (1, 2, [3, 4])
t[2].append(5)
print(t) # Will output (1, 2, [3, 4, 5])
But you cannot do, for example, t[0] = 10 — this will raise a TypeError.