Python-Quizzes | Python Dictionary Quiz | Question 24

Question 24:Find the output of the following program:

filter_none

edit
close

play_arrow

link
brightness_4
code

dictionary = {1:'1', 2:'2', 3:'3'
del dictionary[1
dictionary[1] = '10'
del dictionary[2
print (len(dictionary) )

chevron_right


(A) 1
(B) 2
(C) 3
(D) 4


Answer: (B)

Explanation: The task of the ‘del’ function is to remove key-value pairs from a dictionary. Initially the size of the given dictionary was 3. Then the key value pair for key 1 is first removed and then added back with a new value. Then the key value pair for key 2 is removed. So, finally the size of the dictionary is 2.

Quiz of this Question

My Personal Notes arrow_drop_up
Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.