Skip to content

Instantly share code, notes, and snippets.

@ericdke
Created July 2, 2014 12:07
Show Gist options
  • Save ericdke/f33a4e42c7889ce61291 to your computer and use it in GitHub Desktop.
Save ericdke/f33a4e42c7889ce61291 to your computer and use it in GitHub Desktop.
PYTHON: switch case
dictSwitch = {
humain : saluer,
chien : caresser,
lapin : manger,
poney : monter,
}
# Supposons qu'on ait une variable intitulée "raceEtreVivant", qui vaut : humain, chien, ... ou n'importe quoi d'autre.
# On récupère l'action à faire. Si aucune action de prévue, on récupère la fonction par défaut : regarder.
actionAFaire = dictSwitch.get(raceEtreVivant, regarder)
# On exécute l'action.
actionAFaire()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment