Skip to content

Instantly share code, notes, and snippets.

@Rembane
Created October 6, 2011 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Rembane/1268487 to your computer and use it in GitHub Desktop.
Save Rembane/1268487 to your computer and use it in GitHub Desktop.
Switch-case-statement in Python with default-statement
# Taken from row 21 in https://github.com/emilybache/Refactoring-Katas/blob/master/Tennis/python/tennis.py
result = {
0 : "Love-All",
1 : "Fifteen-All",
2 : "Thirty-All",
3 : "Forty-All",
}.get(self.p1points, "Deuce")
# The .get(key, default)-part returns the value with key key if found, else the default.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment