Python – Dictionary:

Dictionaries are created or indexed by key-value pairs. In which keys are immutable type.

Tuples can be used as keys, but lists cannot be used as keys. Just because lists are mutable.

Generally, the key-value pairs which are stored in the Dictionary can be accessed with the key. we can delete a key value too.


>>> score={'maths':80,'physics':70,'chemistry':85}

>>> score
{'physics': 70, 'maths': 80, 'chemistry': 85}
>>> score['maths']
>>> del score['maths']

>>> score['maths']
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: 'maths'
>>> score
{'physics': 70, 'chemistry': 85}
dict_keys(['physics', 'chemistry'])
>>> keys=score.keys()

>>> keys
dict_keys(['physics', 'chemistry'])
>>> list(keys)
['physics', 'chemistry']