Created
July 28, 2020 13:29
-
-
Save FerdinaKusumah/d56b51eb15d71dcc4f0dbac69319d69d to your computer and use it in GitHub Desktop.
[Python] Get default value from dict
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 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