switch
Benjamin Kaplan
benjamin.kaplan at case.edu
Tue Dec 8 21:00:59 EST 2009
On Tue, Dec 8, 2009 at 8:53 PM, hong zhang <henryzhang62 at yahoo.com> wrote:
> List,
>
> Python does not have switch statement. Any other option does similar work?
> Thanks for help.
>
Use a dict instead, where the keys are the different cases and the
values are usually callable objects (such as functions)
options = {"a" : do_a, "b",do_b, "c", do_c}
option = "a"
try :
options[option]()
except KeyError :
do_default()
> --henry
>
>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
More information about the Python-list
mailing list