Python Programming - Dictionaries - Discussion

Discussion Forum : Dictionaries - General Questions (Q.No. 23)
23.
How do you remove a key-value pair from a dictionary in Python without raising an error if the key is not present?
dictionary.remove_key(key)
dictionary.delete(key)
dictionary.remove(key)
dictionary.pop(key, None)
Answer: Option
Explanation:
The pop() method with a default value of None removes a key-value pair from a dictionary without raising an error if the key is not present.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.