Q:

add value to python dictionary

dict = {'key1':'geeks', 'key2':'for'} 
print("Current Dict is: ", dict) 
  
# adding key3 
dict.update({'key3':'geeks'}) 
print("Updated Dict is: ", dict) 
  
# adding dict1 (key4 and key5) to dict 
dict1 = {'key4':'is', 'key5':'fabulous'} 
dict.update(dict1) 
print(dict) 
  
# by assigning  
dict.update(newkey1 ='portal') 
print(dict) 
4
dict[key] = value
14
student_scores = {'Simon': 45  }
print(student_scores)
# {'Simon': 45}
student_scores['Sara'] = 63
print(student_scores)
# {'Simon': 45, 'Sara': 63}
2
d={'a': 1,'b':2,'c':3}
d['d']=100                # to add  keys and values in dicionary 
1
a_dictonary = {}
a_dictonary.update({"Key": "Value"})
0

New to Communities?

Join the community