Q. Suppose that D is the dictionary {"what" : 22, "are" : 11, "you" : 14, "doing" : 5, "next" : 9, "Saturday?" : 4}. Write down what the value of D is after each of the following Python statements. Evaluate each statement starting with the same value of the dictionary D, mentioned above and write what will be the change dictionary D?
(a) D ["what"] = D ["are"]
(b) D.update ({"Sunday":25, "what":5})
(c) del D["you"]
(d) D ["which"] = 19
(e) D.clear ()
Answer =
(a) >>> D = {"what" : 22, "are" : 11, "you" : 14, "doing" : 5, "next" : 9, "Saturday?" : 4} >>> D ["what"] = D ["are"] >>> D {'what': 11, 'are': 11, 'you': 14, 'doing': 5, 'next': 9, 'Saturday?': 4} >>> (b) >>> D = {"what" : 22, "are" : 11, "you" : 14, "doing" : 5, "next" : 9, "Saturday?" : 4} >>> D.update ({"Sunday":25, "what":5}) >>> D {'what': 5, 'are': 11, 'you': 14, 'doing': 5, 'next': 9, 'Saturday?': 4, 'Sunday': 25} >>> (c) >>> D = {"what" : 22, "are" : 11, "you" : 14, "doing" : 5, "next" : 9, "Saturday?" : 4} >>> del D["you"] >>> D {'what': 22, 'are': 11, 'doing': 5, 'next': 9, 'Saturday?': 4} >>> (d) >>> D = {"what" : 22, "are" : 11, "you" : 14, "doing" : 5, "next" : 9, "Saturday?" : 4} >>> D ["which"] = 19 >>> D {'what': 22, 'are': 11, 'you': 14, 'doing': 5, 'next': 9, 'Saturday?': 4, 'which': 19} >>> (e) >>> D = {"what" : 22, "are" : 11, "you" : 14, "doing" : 5, "next" : 9, "Saturday?" : 4} >>> D.clear () >>> D {} >>>
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )