[Tutor] Switch or Select?
Hernan Martinez Foffani
hernan@orgmf.com.ar
Fri, 11 Oct 2002 15:30:40 +0200
[James.Rocks@equant.com]
> Just curious ... is there any kind of switch or select statement in
> Python? I know there is if/elif/else but a switch/case/else/break
> style control structure would be quite handy :-)
In general you can do it with a chain of elif.
If you want to dispatch code based on a scalar value, a dictionary
of functions may be a better aproach.
The only case (pun intended) were a switch construct may help is
when evaluating ranges. It was considered before but there were
not consensus on syntax and semantics.
Regards,
-Hernan