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
Article Tags :
Recommended Articles