How to code a series of alternatives
F. Petitjean
littlejohn.75 at news.noos.fr
Mon Feb 23 14:08:16 EST 2004
On Mon, 23 Feb 2004 18:28:03 -0000, Scott F <> wrote:
> testvar = bob
I suppose you mean : testvar = "bob"
> # Trial A: This does not work
> if testvar == ("fred" or "bob):
> statements
How about this ?
if testvar in ("fred", bob"):
statements
>
> # Trial B: This does work
> if textvar == "fred" or textvar == "bob":
> statements
>
>
> Trial B is OK for 1 or 2 tests, but gets messy for 5 or 6. What is the
> variation of Trial A that will work?
alternatives = ("one", "two", "three")
if alternative in alternatives:
# statements
Regards
More information about the Python-list
mailing list