setdefault sets the value corresponding to the given key if it is not already in the dictionary : setdefault « Dictionary « Python Tutorial






# when the key is missing, setdefault returns the default and updates the dictionary accordingly. 


d = {}
d.setdefault('name', 'N/A')
d['name'] = 'Gumby'
d.setdefault('name', 'N/A')
print d








8.23.setdefault
8.23.1.setdefault sets the value corresponding to the given key if it is not already in the dictionary
8.23.2.setdefault(): set a default value and then return it.