Python Programming - Dictionaries - Discussion

Discussion Forum : Dictionaries - General Questions (Q.No. 3)
3.
What is the purpose of the dictionary.setdefault(key, default_value) method?
Sets the default value for a key.
Retrieves the default value for a key.
Adds a new key-value pair with a default value.
Removes a key from the dictionary.
Answer: Option
Explanation:
The setdefault() method sets the default value for a key if the key is not present in the dictionary.
Discussion:
Be the first person to comment on this question !

Post your comments here:

Your comments will be displayed after verification.