8
Question Question 8
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 ( )Output
Dictionary contents
5 : number numbernumbernumber
a : string stringstringstring
(1, 2) : tuple tupletupletuple
Explanation
d1 is a dictionary containing three key-value pairs.x in d1.keys() represents that x will iterate on the keys of d1.
The iterations are summarized below:
| x | d1[x] | d1[x] * 3 |
|---|---|---|
| 5 | number | numbernumbernumber |
| a | string | stringstringstring |
| (1,2) | tuple | tupletupletuple |