Computer Science, asked by srivallipichaiyan07, 6 months ago

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 varshamittal029
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