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
>>>


2 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post