0
Can I enter a new pair in dictionary after creating it
Ex- a1={ 'hi' : 8 , 'hello' : 9} Can I make it a1 = {'hi' : 8 , 'hello' : 9 , 'hey' : 10 } If yes how
2 Answers
+ 4
a1['hey'] = 10
0
There are many ways to update a dictionary. As Avinesh said, the most common way is to do as he did.
But some times, you need to update many pairs. That is where you will use the '.update' method :
dct.update((("key", 10), ("other", 3)))
Here, the dict is updated from a tuple of pairs.
You can also update the dictionary from another dictionary :
dct.update({"key": 10, "other": 3})