[Pythonmac-SIG] If/else vs or

Daniel O'Donovan dan.odonovan at gmail.com
Thu Oct 28 17:10:24 CEST 2010


On 28 Oct 2010, at 15:21, Dan Ross wrote:

>     if x == 'red' or 'green' or 'blue':
> 
>     if x == 'red' or 'green' or 'blue':

I think your logic might need straightening here, you're saying

if (x == 'red') 
	or 
if 'green' 
	or 
if 'blue'


but I think you mean

if (x == 'red') 
	or 
if (x == 'green') 
	or 
if (x == 'blue')

so try this

if (x == 'red') or (x == 'green') or (x == 'blue'):

or maybe even

if x in ('red', 'green', 'blue'):

*oops* I see Ronald has got his answer in first!


HTH 

Dan

Daniel O'Donovan
dan.odonovan at gmail.com





More information about the Pythonmac-SIG mailing list