Created
July 2, 2014 12:07
-
-
Save ericdke/f33a4e42c7889ce61291 to your computer and use it in GitHub Desktop.
PYTHON: switch case
This file contains 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
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