Skip to content

Instantly share code, notes, and snippets.

@FerdinaKusumah
Created July 28, 2020 13:29
Show Gist options
  • Save FerdinaKusumah/d56b51eb15d71dcc4f0dbac69319d69d to your computer and use it in GitHub Desktop.
Save FerdinaKusumah/d56b51eb15d71dcc4f0dbac69319d69d to your computer and use it in GitHub Desktop.
[Python] Get default value from dict
"""Get value from dictionary with default value"""
fruits = dict()
fruits["apple"] = 2
fruits["banana"] = 3
# {'apple': 2, 'banana': 3}
pear = fruits.get("pear", 3)
print(pear)
# 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment