add to dictonary 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: add value to dictionary python
dict[key] = value
Example 3: python dictoinary add value
student_scores = {'Simon': 45 }
print(student_scores)
# {'Simon': 45}
student_scores['Sara'] = 63
print(student_scores)
# {'Simon': 45, 'Sara': 63}