1dict_append = {"1" : "Python", "2" : "Java"}
2dict_append.update({"3":"C++"}) # append doesn't supported in dict
3 # instead , use update in dict
4print(dict_append)
5# output : {'1': 'Python', '2': 'Java', '3': 'C++'}
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)
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)