Somehow, this works:
def in_range(min, test, max):
return min <= test <= max
print in_range(0, 5, 10) # True
print in_range(0, 15, 10) # False
However, I can't quite figure out the order of operations here. Let's test the False
case:
print 0 <= 15 <= 10 # False
print (0 <= 15) <= 10 # True
print 0 <= (15 <= 10) # True
Clearly, this isn't resolving to a simple order of operations issue. Is the interval comparison a special operator, or is something else going on?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…