I'm a newbie at Python. This is my code right here. When I do not add parenthesis around x<=y<=z
it gives me a false bool value in return and the if statement doesn't run.
def is_between(x,y,z):
return x<=y<=z==1
if is_between(1,2,4):
print('y is between x and z')
But if I add the parenthesis, it works perfectly fine. But why is this happening? I checked operator precedence and <=
has higher precedence than the ==
operator. Shouldn't x<=y<=z
evaluate first even if I don't add those parentheses?
def is_between(x,y,z):
return (x<=y<=z)==1
if is_between(1,2,4):
print('y is between x and z')