I need newbie help
Paul McNett
p at ulmcnett.com
Fri May 14 01:26:56 EDT 2004
Sean Berry writes:
> You have to read the whole page to understand why.
>
> The title is: Python style switches.
> Python does not have a swith statement like many other
> languages. A switch statement could look like this:
>
> switch (a)
> case 1: do something
> case 2: do something else
> case 3: do something else
> default: do something else
>
> It evaluates a and checks to see if there is a matching case.
> If there is, it executes the code for that case. So if
> a==1, it would "do something."
What's the matter with using if...elif...else:
if case1: # do something
elif case2: # do something else
elif case3: # do something else
else: # do the default something else
--
Paul
More information about the Python-list
mailing list