18
Question Question 18
What will the following code do?
d = {"Phy":94, "Che":70, "Bio":82, "Eng":95}
d.update({"Che":72, "Bio":80})- It will create new dictionary as dict={"Che":72,"Bio":80} and old d will be deleted.
- It will throw an error as dictionary cannot he updated.
- It will simply update the dictionary as dict={"Phy":94, "Che":72, "Bio":80, "Eng":95}.
- It will not throw any error but it will not do any changes in dict.
It will simply update the dictionary as:
d = {"Phy":94, "Che":72, "Bio":80, "Eng":95}.
Reason — The update() method updates the dictionary with the elements from another dictionary object or from an iterable of key/value pairs.
Here {"Che":72, "Bio":80} represents another dictionary with the help of which original d is updated i.e. the value of keys: "Che" and "Bio" are updated to 72 and 80 respectively.