What will be the output of the following Python 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) Method update() doesn’t exist for dictionaries
c) {1: ‘A’, 2: ‘B’, 3: ‘C’, 4: ‘D’, 5: ‘E’}
d) {4: ‘D’, 5: ‘E’}
Answers
Answered by
1
Answer: Option (c) is correct.
Concept:
The update( ) method updates the dictionary with the provided elements.
Given:
a={1:"A",2:"B",3:"C"}
b={4:"D",5:"E"}
a.update(b)
print(a)
Find:
What will be the output of the given Python code?
Solution:
The dictionary is updated with items from another dictionary object or an iterable of key/value pairs using the update() method.
Syntax: dictionary.update(iterable)
Here two dictionaries are given.
a={1:"A",2:"B",3:"C"}
b={4:"D",5:"E"}
a.update(b) will insert dictionary b into dictionary a.
Therefore matrix a would be:
{1: 'A', 2: 'B', 3: 'C', 4: 'D', 5: 'E'}
Hence option (c) is the correct option.
Output:
{1: 'A', 2: 'B', 3: 'C', 4: 'D', 5: 'E'}
Similar questions
CBSE BOARD X,
2 months ago
Hindi,
2 months ago
English,
2 months ago
Accountancy,
6 months ago
Math,
6 months ago
Chemistry,
11 months ago