Skip to content
Related Articles

Related Articles

Python-Quizzes | Python Dictionary Quiz | Question 3
  • Last Updated : 17 Sep, 2020

Question 3:Find the output of the following program:




D = {1 : {'A' : {1 : "A"}, 2 : "B"}, 3 :"C", 'B' : "D", "D": 'E'
print(D[D[D[1][2]]], end = " "
print(D[D[1]["A"][2]]) 

(A) C B
(B) E Key Error
(C) B D
(D) D B


Answer: (B)

Explanation: Key-Value Indexing is used in the example above. D[1] = {‘A’ : {1 : “A”}, 2 : “B”}, D[1][2] = “B”, D[D[1][2]] = D[“B”] = “D” and D[“D”] = “E”. D[1] = {‘A’ : {1 : “A”}, 2 : “B”}, D[1][“A”] = {1 : “A”} and D[1][“A”][2] doesn’t exists, thus KeyError.

Quiz of this Question

My Personal Notes arrow_drop_up
Recommended Articles
Page :