Add new key-value pair to a dictionary

To add a new key-value pair to a dictionary, we can use the following syntax:

my_dict = {'eye_color': 'blue', 'height': '165cm', 'weight': '53kg'}
my_dict['age'] = 22

print(my_dict[‘age’])

>>>
22
>>>

In the example above you can see that I’ve added the key called age with and assigned it a value of 22.

The order in which you store each key-value pair in Python in not important. Note that, however, since Python 3.7, dictionaries are ordered. In earlier versions of Python, dictionaries were unordered.
Geek University 2022