Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок+ 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
1 ответ
+ 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 } )