Possible Duplicate:
Why are python strings and tuples are made immutable?
What lower-level design makes tuple not mutable in Python? Why this feature is useful?
Possible Duplicate:
Why are python strings and tuples are made immutable?
What lower-level design makes tuple not mutable in Python? Why this feature is useful?
A few reasons:
__hash__
methods based on their contents, the values returned could change as the contents change, which violates the contract for hash values.tuple
method which will copy only when necessary.Because otherwise there wouldn't be an immutable sequence type! If you want a mutable tuple you just use a list.
Using immutable types when appropriate has various performance perks, and you couldn't easily use a dict
with tuple keys if they were made mutable.