What are dictionaries?

Dictionaries (also known as mappings) are used in Python to store a set of objects by key, so you can connect pieces of related information. Each key in a dictionary is connected to a value. A key can be a number, a string, a list, or even another dictionary. To access the elements of a dictionary, you need to specify its key.

The elements of a dictionary are defined within the curly braces. For example, the following statement will create a three word dictionary:

my_dict = {'eye_color': 'blue', 'height': '165cm', 'weight': '53kg'}

To access the value associated with the key eye_color, we would use the following statement: my_dict[‘eye_color’]:

my_dict = {'eye_color': 'blue', 'height': '170cm', 'weight': '60kg'}
Geek University 2022