+ 1
dictionaries
Only immutable objects can be used as keys to dictionaries. Immutable objects are those that can't be changed. So far, the only mutable objects you've come across are lists and dictionaries. Trying to use a mutable object as a dictionary key causes a TypeError. could you explain more? I am clear with this.
4 ответов
+ 1
If you want to understand in detail, I suggest you to refer to this website:
http://net-informations.com/JUMP_LINK__&&__python__&&__JUMP_LINK/iq/immutable.htm
+ 1
Mutable means modifiable.
Ex: lists, dictionaries.
Immutable means cannot be modifiable.
Ex:
Touples, strings..
Dictionary keys must be immutable. You can change values but not key. If keys are changeable, then other part code may change its values, then you get difficulty in accessing values or you can predict which value stored in which key so Program goes into undefined behaviour.. So that's why it is not allowed to use as keys.
0
amog us
0
thank you, Jayakrishna