1default_data = {'item1': 1,
2 'item2': 2,
3 }
4
5default_data.update({'item3': 3})
6# or
7default_data['item3'] = 3
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# Basic syntax:
2dictionary['new_key'] = value
3
4# Example:
5d = {'a': 1, 'b': 5} # Define dictionary
6d['c'] = 37 # Add a new key to the dictionary
7print(d)
8--> {'a': 1, 'b': 5, 'c': 37}
1>>> d1 = {1: 1, 2: 2}
2>>> d2 = {2: 'ha!', 3: 3}
3>>> d1.update(d2)
4>>> d1
5{1: 1, 2: 'ha!', 3: 3}