Q. What will be the output produced by following code?
d1 = {5 : "number", "a" : "string", (1, 2) : 'tuple'}
print ("Dictionary contents")
for x in d1.keys() : # Iterate on a key list
print (x, ':', d1[x], end = ' ')
print (d1[x] * 3)
print ()
Answer :-
Output : -
Dictionary contents
5 : number numbernumbernumber
a : string stringstringstring
(1, 2) : tuple tupletupletuple
>>>
5 : number numbernumbernumber
a : string stringstringstring
(1, 2) : tuple tupletupletuple
>>>
Explanation :-
x in d1.keys() So, Values of x are keys of Dictionary
print (x, ':', d1[x], end = ' ') It will print key : values of dictionary
print (d1[x] * 3) It will print values three times.
lmao ded
ReplyDelete??
Deletethere in the question it is given to repeat the dx 3 times...but why u repeated 4 times??
ReplyDeleteYou are wrong. Please run it in your idle python.
Deletethis is because in the third last line its executing "x" one and then its executing it again 3 times in second last line.So it will be executed 4times totally...
DeleteCan you explain the code by entering message??
ReplyDeleteOk.
DeletePost a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )