निम्नलिखित कोड का परिणाम क्या है ?
What is the output of the following code ?
a = {1: "A", 2: "B", 3: "C"}
b = {4: "D", 5: "E"}
a.update(b)
print(a) A
{1: 'A', 2: 'B', 3: 'C'}
B
{1: 'A', 2: 'B', 3: 'C', 4: 'D', 5: 'E'}
C
Error
D
{4: 'D', 5: 'E'}
Explanation
The output will be:
(B) {1: 'A', 2: 'B', 3: 'C', 4: 'D', 5: 'E'}
Explanation:
- The
update()method adds key-value pairs from dictionarybinto dictionarya. - After calling
a.update(b), the dictionaryawill now include the key-value pairs fromb. So, the updated dictionaryawill be{1: 'A', 2: 'B', 3: 'C', 4: 'D', 5: 'E'}.
Correct Answer: B) {1: 'A', 2: 'B', 3: 'C', 4: 'D', 5: 'E'}