Python Function Reference

setdefault
If key is in the dictionary, return its value. If not, insert key with a value of default and return default.
Python 3.13
dict.setdefault(key, default=None)
key
The key to look for/insert.
default
The default value.
Examples
Python 3.13
>>> a = {'x': 1}
>>> a.setdefault('y', 2)
2