Modify a value in a dictionary

To modify an existing value in a dictionary, we simply need to assign the new value to the key.

Consider the following example:

my_dict = {'eye_color': 'blue', 'height': '165cm', 'weight': '53kg'}
print('The old weight is:', my_dict['weight'])
my_dict['weight'] = '54kg'
print('The new weight is:', my_dict['weight'])

The old weight is: 53kg
The new weight is: 54kg

In the example above we’ve changed the value of weight to 54kg.

Geek University 2022