Python-Quizzes | Python Dictionary Quiz | Question 2

Question 2:Find the output of the following program:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


(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

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.