Delete a key-value pair in a dictionary

It is really easy to remove a key-value pair from a dictionary – you only need to specify the key you would like to remove.

Here’s an example:

my_dict = {'eye_color': 'blue', 'height': '165cm', 'weight': '54kg'}
del my_dict['height']


{'eye_color': 'blue', 'weight': '54kg'}

In the example above you can see that we’ve deleted the height key.

Geek University 2022