Created
November 6, 2017 15:27
-
-
Save tadone/ce4314bb12d66b4e50975f7173449de2 to your computer and use it in GitHub Desktop.
[Dictionary Return Values] #python
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
# It allows you to provide a default value if the key is missing: | |
dictionary.get("bogus", default_value) | |
# returns default_value (whatever you choose it to be), whereas | |
dictionary["bogus"] | |
# would raise a KeyError. | |
# If omitted, default_value is None, such that | |
dictionary.get("bogus") # <-- No default specified -- defaults to None | |
# returns None just like | |
dictionary.get("bogus", None) | |
# would. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment