Created
December 5, 2019 01:23
-
-
Save FerdinaKusumah/4254523ecf1acb107185cec2222eec84 to your computer and use it in GitHub Desktop.
Get dict key with default value
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""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