Python Dictionary setdefault() Method

0

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

 

 

Post a Comment

0Comments
Post a Comment (0)