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