switch

Steven D'Aprano steven at REMOVE.THIS.cybersource.com.au
Wed Dec 9 01:12:15 EST 2009


On Tue, 08 Dec 2009 21:02:44 -0800, Kee Nethery wrote:

> I string together a bunch of elif statements to simulate a switch
> 
> if foo == True:
> 	blah
> elif bar == True:
> 	blah blah
> elif bar == False:
> 	blarg
> elif ....


Are you sure you want to test for equality with True and False? Generally 
one should write that as:

if foo:
    blah
elif bar:
    blah blah
elif not bar:
    blarg
...




-- 
Steven



More information about the Python-list mailing list