Confusion about immutability (of named tuples)

NamedTuple is an immutable type - you cannot make it mutable.

It’s because you’re not changing the existing object, but creating a new one and binding that to the same name, which replaces the object the name is referring to.

You can think of variable names as labels of an object - assigning an object to a variable means labelling that object with that variable name.

7 Likes