MCPcopy Index your code
hub / github.com/python/cpython / setdefault

Method setdefault

Lib/collections/__init__.py:268–276  ·  view source on GitHub ↗

Insert key with a value of default if key is not in the dictionary. Return the value for key if key is in the dictionary, else default.

(self, key, default=None)

Source from the content-addressed store, hash-verified

266 return default
267
268 def setdefault(self, key, default=None):
269 '''Insert key with a value of default if key is not in the dictionary.
270
271 Return the value for key if key is in the dictionary, else default.
272 '''
273 if key in self:
274 return self[key]
275 self[key] = default
276 return default
277
278 @_recursive_repr()
279 def __repr__(self):

Callers 1

test_setdefaultMethod · 0.95

Calls

no outgoing calls

Tested by 1

test_setdefaultMethod · 0.76