Q. Read the following pieces of code. Determine whether they will be executed successfully not. If yes, show the result that would be printed. If not, explain why not.


(a)
myDictionary1 = { a:1, b:2, c:3}
myDictionary1[d] = 4
print (myDictionary1)

(b)
myDictionary2 = { 10: 1, 20: 2, 30: 3}
print (myDictionary2[1])

Answer :-

(a) It will give error because in dictionary keys should be immutable data type.
(b) It will give error because in dictionary myDictionary1 key 1 is not present.

1 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