python dictionary get vs setdefault
# 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
python dictionary get vs setdefault
# 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
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us