📜  python 字典 get vs setdefault - Python 代码示例

📅  最后修改于: 2022-03-11 14:45:24.805000             🧑  作者: Mango

代码示例1
# setdefault will insert key with a value of default
# get will not insert key

a = {}
b = a.get('key','value')
print(a,b)
# {} value

a = {}
b = a.setdefault('key','value')
print(a,b)
# {'key': 'value'} value