Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

abbreviating a double comparison in python

Tags:

python

Is there a way to abbreviate a comparison statement in python so that I don't have to write the whole thing out again? For example, instead of :

a=3
if a==3 or a==2:
    print "hello world"

could I do something like: if a==(3 or 2): print "hello world"

I know the above example won't work but is there another way i can achieve the desired effect?

like image 293
fergusdawson Avatar asked May 16 '12 19:05

fergusdawson


1 Answers

if a in (2, 3):
  print "hello world"
like image 194
NPE Avatar answered Nov 15 '22 13:11

NPE