Python Dictionary setdefault() Method

Python Dictionary setdefault() Method

  • The setdefault() method returns the value of a key (if the key is in dictionary). If not, it inserts key with a value to the dictionary.

Syntax

  • dictionary.setdefault(keyname, value)

Parameter Values

  • value of the key if it is in the dictionary

  • None if key is not in the dictionary and default_value is not specified

  • default_value if key is not in the dictionary and default_value is specified

 

 

Comments