Informatics Practices

Consider the given code:

D1={1: 'India', 2: 'Russia', 3: 'World'}
D2={'School' : 'EOIS' , 'Place ' : 'Moscow'}
print(D1.update (D2) )

What will be the output of the above code:

  1. None
  2. {1: 'India' , 2: 'Russia' , 3: 'World' , 'School' : 'EOIS' , 'Place' : 'Moscow'}
  3. Error
  4. None of these

Python Dictionaries

2 Likes

Answer

None

Reason — The output is "None" when using print(D1.update(D2)) because the update() method for dictionaries modifies the dictionary in place. It does not return the updated dictionary itself; instead, it returns "None".

Answered By

2 Likes


Related Questions