Home »
Python »
Python Dictionary MCQs
What will be the output of the following code? | Dictionary Que. 30
30. What will be the output of the following code?
d = {'x': 1, 'y': 2, 'z': 3}
a = d.pop('y')
print(a, d)
- 2 {'x': 1, 'z': 3}
- 0 {'x': 1, 'z': 3}
- 2 {'x': 1, 'y' : 2, 'z': 3}
- None
Answer: A) 2 {'x': 1, 'z': 3}
Explanation:
The pop() method will remove the element, and returns the value. Here, we are removing the element whose key is 'y'. The method will return it value which is 2. Thus, the output of the above code will be:
2 {'x': 1, 'z': 3}