Q. What will be the output of the following code snippet?
dc1 = {}
dc1[1] = 1
dc1['1']= 2
dc1[1.0] =4
sum = 0
for k in dc1:
sum += dc1[k]
print (sum)
Answer :-
6
>>>
Explanation :-
At first Our dictionary is :- {1: 4, '1': 2}
her dc1[1] = 1 will not work because 1 is same as 1.0 in dc1[1.0] =4
so dc1[1.0] =4.
So, our output is sum of values that is 2 + 4 = 6.
How?
ReplyDeleteI have added Explanation.
Deletethx
ReplyDeleteWelcome 😊😊
Deletenice
ReplyDeleteWelcome : )
DeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )