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

30th Aug 2020, 5:53 PM
Krishna Agrawal
Krishna Agrawal - avatar
2 Answers
+ 4
a1['hey'] = 10
30th Aug 2020, 5:58 PM
Avinesh
Avinesh - avatar
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})
30th Aug 2020, 7:11 PM
Théophile
Théophile - avatar