1# to add key-value pairs to a dictionary:
2
3d1 = {
4 "1" : 1,
5 "2" : 2,
6 "3" : 3
7} # Define the dictionary
8
9d1["4"] = 4 # Add key-value pair "4" is key and 4 is value
10
11print(d1) # will return updated dictionary
1d = {'a': 1, 'b': 2}
2print(d)
3d['a'] = 100 # existing key, so overwrite
4d['c'] = 3 # new key, so add
5d['d'] = 4
6print(d)
1testing1={'one':1,'two':2}
2''' update() is the method of dict() merges another dict into existing ones '''
3''' it replaces the keys of exisiting ones with the the new ones '''
4testing1.update({'two':3,'noice':69})
5print(testing1) """ {'one':1,'two':3,'noice':69} """
1dict = {1 : 'one', 2 : 'two'}
2# Print out the dict
3print(dict)
4# Add something to it
5dict[3] = 'three'
6# Print it out to see it has changed
7print(dict)
1# This automatically creates a new element where
2# Your key = key, The value you want to input = value
3dictionary_name[key] = value