Computer Science

Write the output of the code given below:

d1 = {"A" : "Avocado", "B" : "Banana"} 
d2 = {'B' : 'Bag', 'C' : 'Couch'}
d2.update(d1)
print(len(d2))

Python

Python Dictionaries

3 Likes

Answer

Output
3

Working

The code initialize two dictionaries, d1 and d2, with key-value pairs. Then, it updates d2 with the key-value pairs from d1, overwriting the value of key 'B' in d2 with 'Banana' from d1 and adding the new key-value pair 'A' mapped to 'Avocado'. Finally, it prints the length of d2, which is 3 since d2 now has three key-value pairs after the update operation.

Answered By

1 Like


Related Questions