Python does not have a built-in switch case statement like some other programming languages. However, we can achieve similar functionality using conditional statements. Here is an example:
main.py361 chars18 linesIn the above code snippet, we have defined a switcher dictionary that maps the cases to their corresponding values. We then call switcher.get(argument, "Invalid month") to get the corresponding value for the given argument.
Here is an example usage:
main.py164 chars6 lines
Note that the second argument to get() (i.e., "Invalid month") is the default value returned if the argument is not found in the switcher dictionary.
gistlibby LogSnag