dictionaries | SoloLearn: Learn to code for FREE!

0

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/19/2020 12:55:42 AM

PRIYANKA K

2 Answers

New Answer

0

If you want to understand in detail, I suggest you to refer to this website: http://net-informations.com/python/iq/immutable.htm

0

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.