As answered by 101 and d-coder, your question to find a value between two other values should be constructed using <
or <=
operators, depending on what you want. Assuming that you know that r is a simple collection, like a list or tuple or range, but you don't know it's ordering, you could write:
>>> r = (-1,4,2,3,0)
>>> min(r) < 3 < max(r)
True
>>> min(r) < 2.5 < max(r)
True
The in
operator on the other hand will test whether your value is one of the values in the list
>>> 3 in r
True
>>> 2.5 in r
False
Finally, your first example failed because you did not specify a negative step when trying to define 'r' as a decreasing sequence. Here's an example where I'll specify a step size of -2 as the 3rd argument of range()
:
>>> a = range(4,-1)
>>> print a
[]
>>> b = range(5,-1,-2)
>>> print b
[5, 3, 1]
>>> 3 in a
False
>>> 3 in b
True