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)
  1. 2 {'x': 1, 'z': 3}
  2. 0 {'x': 1, 'z': 3}
  3. 2 {'x': 1, 'y' : 2, 'z': 3}
  4. 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}

Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.