Skip to content

Instantly share code, notes, and snippets.

@tadone
Created November 6, 2017 15:27
Show Gist options
  • Save tadone/ce4314bb12d66b4e50975f7173449de2 to your computer and use it in GitHub Desktop.
Save tadone/ce4314bb12d66b4e50975f7173449de2 to your computer and use it in GitHub Desktop.
[Dictionary Return Values] #python
# 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