Open In App

Python-Quizzes | Python Dictionary Quiz | Question 2

Like Article
Like
Save
Share
Report

Question 2:Find the output of the following program:




D = {1 : 1, 2 : '2', '1' : 1, '2' : 3
D['1'] = 2
print(D[D[D[str(D[1])]]]) 


(A) 2
(B) 3
(C) ‘2’
(D) KeyError


Answer: (B)

Explanation: Simple key-value pair is used recursively, D[1] = 1, str(1) = ‘1’. So, D[str(D[1])] = D[‘1’] = 2, D[2] = ‘2’ and D[‘2’] = 3.

Quiz of this Question


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