Open In App
Related Articles

Python-Quizzes | Python Dictionary Quiz | Question 3

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report
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

Last Updated : 17 Sep, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads