Python-Quizzes | Python Dictionary Quiz | Question 3

Question 3:Find the output of the following program:

filter_none

edit
close

play_arrow

link
brightness_4
code

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]]) 

chevron_right


(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
Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.