1d = {'key':'value'}
2print(d)
3# {'key': 'value'}
4d['mynewkey'] = 'mynewvalue'
5print(d)
6# {'mynewkey': 'mynewvalue', 'key': 'value'}
7
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
1dict_1 = {"1":"a", "2":"b", "3":"c"}
2dict_2 = {"4":"d", "5":"e", "6":"f"}
3
4dict_1.update(dict_2)
5print(dict_1)
6#Output = {"1":"a", "2":"b", "3":"c", "4":"d", "5":"e", "6":"f"}
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)
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} """