python && statement????

Associate
Joined
23 Aug 2004
Posts
1,493
Does anyone know how to code 'AND' in python for if statements?

I want to say

Code:
if expression >= -0.25 and expression <= 0.25
then stop

Can't find the and operator to do it though!
 
should be....
Code:
exp=float(exp)#Just in case ;)
if (exp >=-0.25) and (exp <=0.25):
    exit()#or break... whatever....


Got a little bored so made a quick function... :D
Code:
>>> def test(x):
...  x=float(x)
...  if(x>=-0.25) and (x<=0.25):
...   print 'Within'
...
>>> test(0.3)
>>> test(0.1)
Within
>>> test(-0.1)
Within
>>> test(-0.3)
>>>
 
Last edited:
Back
Top Bottom