The dictionary
or dict
is used to store key-value pairs in one variable.
dictionary_name = {"key1": value1, "key2": value2}
dictionary_name["key3"] = value3
dictionary_name["key1"]
Note:
>>> days_of_week = {'Monday': 'mon', 'Tuesday': 'tues'}
>>> # Add a new key-value pair
>>> days_of_week['Wednesday'] = 'wed'
>>> days_of_week
{'Monday': 'mon', 'Tuesday': 'tues', 'Wednesday': 'wed'}
>>> print (days_of_week['Monday'])
'mon'