Professional Documents
Culture Documents
PDF document-095240A8024B-1
PDF document-095240A8024B-1
method
Dictionary in Python is an unordered collection of data values, used to
store data values like a map, which unlike other Data Types that hold
only single value as an element, Dictionary holds key : value pair.
In Python Dictionary, 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.
Example #1:
Python3
Dictionary1 = { 'A': 'Geeks', 'B': 'For', 'C': 'Geeks'}
Third_value = Dictionary1.setdefault('C')
:
print("Dictionary:", Dictionary1)
print("Third_value:", Third_value)
Output:
Python3
Dictionary1 = { 'A': 'Geeks', 'B': 'For'}
Third_value = Dictionary1.setdefault('C')
print("Dictionary:", Dictionary1)
print("Third_value:", Third_value)
print("Dictionary:", Dictionary1)
print("Fourth_value:", Fourth_value)
Output: