Page 1 of 1

OR in python?

Posted: Tue Feb 23, 2010 12:58 am
by Fiasco
Silly question (perl programmer here)

How do I do

if x == 1 or x == 2:
execute this

in python?

Re: OR in python?

Posted: Tue Feb 23, 2010 1:01 am
by Fiasco
Figures it out 10 seconds later

if (x == 1) | (x==2):

Re: OR in python?

Posted: Tue Feb 23, 2010 6:05 pm
by Bartman
You could have it written exactly as in the question

Code: Select all

if x == 1 or x == 2:
In your answer you actually do a bitwise combination of to boolean values.