for doubts about variable objects, please give us some advice. Thank you!
problem description:
-
The element of
- tuple
tuplecan only hold immutable objects, and the element in it can be listlist, because what is actually stored is the address of the list (variable object). As long as the address of the variable list remains the same, even if the elements in the list change, it cannot be said to be a change of tuple elements.
The key of the - dictionary
dictcannot be a mutable element because you need to use key to hash the value. If key is a list (mutable object) at this time, the dictionary will report an error:TypeError: unhashable type: "list".
then the problem arises:
is also a variable element list . Why is it legal and immutable to take the address in the tuple tuple , but the value as key in the dictionary dict is illegal, takes value , and is variable.
such a design does not feel consistent in use or intuitive understanding, because the rules are inconsistent.
