Q. Which of the following will result in an error for a given valid dictionary D?


(i)

D + 3


(ii)

D * 3


(iii)

D + {3 : "3"}


(iv)

D.update ({3 : "3"})


(v)

D.update({"3" : 3})


(vi)

D.update("3": 3)


Answer:-


Options (i), (ii), (iii), & (vi)


The explanation for (i):- We can not add the number to the dictionary because the dictionary has keys and value pairs.


Explanation for (ii):- We can not do arithmetic operations on the dictionary directly.


Explanation for (iii):- We can not directly add keys and value pairs. Correct way : D[3] = "3"


Explanation for (vi):- We have to pass the dictionary in the update function.

13 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post