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:
- None
- {1: 'India' , 2: 'Russia' , 3: 'World' , 'School' : 'EOIS' , 'Place' : 'Moscow'}
- Error
- 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
3 Likes
Related Questions
Which of the following functions will return key-value pairs of the dictionary in the form of list of tuples?
- key()
- values()
- items()
- get()
Select the correct option to get the values of marks key:
Student={ "name" : "Emma", "class" :11, "sec": "a", "marks" :76}- Student.get(3)
- Student.get("marks")
- Student["marks"]
- Both 2 and 3
Assertion (A): Dictionary is a collection of key-value pairs.
Reasoning (R): Each key in a dictionary maps to a corresponding value. Keys are unique and act as the index.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
Assertion (A): Dictionaries are enclosed within curly braces { }.
Reasoning (R): The key-value pairs are separated by commas (,).
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.