MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/badcode/comments/ok1itb/tryexcept_in_python_sigh/h5lfv56/?context=3
r/badcode • u/lonaExe • Jul 14 '21
93 comments sorted by
View all comments
Show parent comment
2
It's like dict.get(), but if the item does not exist, the default will be returned and the default will be set as the value for the key.
dict.get()
>>> x = {"a": "b"} >>> print(x.setdefault("a", "d") b >>> print(x.setdefault("c", "d") d >>> x {"a": "b", "c": "d"}
View all comments
Show parent comment
2
u/[deleted] Jul 18 '21
It's like
dict.get(), but if the item does not exist, the default will be returned and the default will be set as the value for the key.