Skip to content

Instantly share code, notes, and snippets.

@FerdinaKusumah
Created December 5, 2019 01:23
Show Gist options
  • Save FerdinaKusumah/4254523ecf1acb107185cec2222eec84 to your computer and use it in GitHub Desktop.
Save FerdinaKusumah/4254523ecf1acb107185cec2222eec84 to your computer and use it in GitHub Desktop.
Get dict key with default value
"""Get dictionary value and set default value when not exists"""
a = dict()
a['apple'] = 10
a['banana'] = 12
print(a)
# {'apple': 10, 'banana': 12}
"""Print print wheneather not exists value and set default value"""
print(a.get('pear', 5))
# 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment