Q:

adding one element in dictionary python

d = {'key':'value'}
print(d)
# {'key': 'value'}
d['mynewkey'] = 'mynewvalue'
print(d)
# {'mynewkey': 'mynewvalue', 'key': 'value'}
21
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
mydict = {'score1': 41,'score2': 23}
mydict['score3'] = 45			# using dict[key] = value
print(mydict)
5

New to Communities?

Join the community