19
Question Question 19
What will be the result of the following code?
d = {"Jo":1,"Ra":2}
d.update({"Phoebe":2})
print(dict)- {"Jo":1,"Ra":2,"Ph":2}
- {"Jo":1,"Ra":2}
- {"Jo":1,"Ph":2}
- Error
{'Jo': 1, 'Ra': 2, 'Phoebe': 2}
Reason — The update() method updates the dictionary with the elements from another dictionary object or from an iterable of key/value pairs.
Here, {"Phoebe":2} is a dictionary of key named "Phoebe" which is not present in dict. Therefore, update function will add this key and its corresponding value to original dictionary dict.
Note: There is a misprint in the options provided in the book.