Python Dictionary setdefault() method

The dictionary.setdefault () method in Python returns the value of the item with the specified key.

Syntax

Parameter

keyname- This parameter represents the keyname of the item you want to return the value.

value(optional)- This parameter represents a Key with a value default_value is inserted to the dictionary. If no value is provided, the default_value will be none. 

Return

This method returns an arbitrary element (key, value) pair from the given dictionary.

Example 1

Output

Example 2

Output

Pin It on Pinterest

Share This