set key in dictionary python code example
Example 1: how to set a key of dict in python
# declaring dict
dictionary={'Hello':3,'World!':4}
# creating function
def dict_add(obj,key,value):
obj[key]=value
reutrn obj
# using the functiom
dict_add(dictionary,'Python',10)
print (dictionary) # output --> { 'Hello':3 ,'World!':4 , 'Python':10 }
Example 2: append dictionary python
>>> d1 = {1: 1, 2: 2}
>>> d2 = {2: 'ha!', 3: 3}
>>> d1.update(d2)
>>> d1
{1: 1, 2: 'ha!', 3: 3}