Two ways to add a key value pair to a dictionary, which one to use? [Solved] | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Two ways to add a key value pair to a dictionary, which one to use? [Solved]

Hello everyone, this is a dictionary and i have a question related to this. We have two ways to add a key value pair in a dictionary. I have a question that which one will the the most covenient to use. Or is there any difference between their usage. Plz advise me, i am a beginner https://code.sololearn.com/c6M96Ixhhs0x/?ref=app

14th Jan 2021, 2:54 AM
∆BH∆Y
∆BH∆Y - avatar
1 Answer
+ 3
If you only wany to update or insert one pair, then use: dict[ key ] = value If you want to update or insert multiple keys and values, use dict.update() dict.update( { key1: val1, key2: val2, key3: val3 } )
14th Jan 2021, 3:01 AM
noteve
noteve - avatar