CBSE Class 12 Computer Science Question 27 of 43

Practice Paper — Question 9

Back to all questions
9
Question

Question 23(b)

Write the output of the code given below:

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

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.