Python: Properties of Dictionary Keys

There are two important points while using dictionary keys. 

1. More than one entry per key is not allowed ( no duplicate key is allowed).

dict_1 = {1:'a',2:'b',1:'c',4:'d'}
print(dict_1[1])

Output: c

2. The values in the dictionary can be of any type, while the keys must be immutable like numbers, tuples, or strings ,and keys are also case sensitive.

dict_1 = {[1]:'a',2:'b',3:'c'}
print(dict_1)

Output: TypeError: unhashable type: 'list'

Tags