DEV Community

Discussion on: Dead Simple Python: Data Typing and Immutability

Collapse
 
codemouse92 profile image
Jason C. McDonald

You've got the list examples exactly right. That's how mutable copies work.

Regarding immutable types, like tuples, the first part is the same.

t1 = (1,2,3)
t2 = t1 #points to same location as pointed by t1
t3 = t2 #points to same location as pointed by t1
t4 = t3 #points to same location as pointed by t1

You are correct that an immutable type doesn't support append. As the word "immutable" suggests, the value cannot be mutated, or modified.

However, we can reassign.

t3 = (4,5,6) # t3 now points to (4,5,6). t1, t2, t4 still point to (1,2,3)

P.S. I'm rewriting this explanation in the book to be even clearer.