Why is the tuple not changed in Python?

Possible duplicate:
Why do python strings and tuples become immutable?

What low-level project makes a tuple not mutable in Python? Why is this feature useful?

+5
source share
2 answers

A few reasons:

  • Forbidden objects, such as lists, cannot be used as dictionary keys or set elements in Python, since they are not hashable . If methods were provided for lists __hash__based on their contents, the return values ​​might change as the contents change, which violates the contract for hash values.
  • Python , , , , , . , . , tuple, .
+24

! , .

, dict , .

+1
source

All Articles