Q. Predict the output:
(a)
d = {(1, 2):1, (2, 3):2}
print (d[1, 2])
(b)
d = {'a': 1, 'b':2, 'c':3}
print (d['a', 'b'])
Answer :-
(a)
1
>>>
>>>
Because 1,2 is the key of the dictionary it can be written as d[ ( 1, 2 ) ].
(b)
Error : (
Because there must be only one key in the square bracket. So, the correct code is:-
print( d['a'] , d['b'] )
So, the Output will be:-
Because there must be only one key in the square bracket. So, the correct code is:-
print( d['a'] , d['b'] )
So, the Output will be:-
1 2
>>>
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )