Skip to content

Instantly share code, notes, and snippets.

@etigui
Last active November 10, 2018 09:40
Show Gist options
  • Save etigui/a28e2140086c4e2e10e0e5ae52644288 to your computer and use it in GitHub Desktop.
Save etigui/a28e2140086c4e2e10e0e5ae52644288 to your computer and use it in GitHub Desktop.
Python default argument return when "get()" is called if the given key not exists in the dict (PyTricks)
# The get() method on dicts
# and its "default" argument
name_for_userid = {
382: "Alice",
590: "Bob",
951: "Dilbert",
}
def greeting(userid):
return "Hi %s!" % name_for_userid.get(userid, "there")
>>> greeting(382)
"Hi Alice!"
>>> greeting(333333)
"Hi there!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment