To check whether some number n is in the inclusive range denoted by the two number a and b you do either
if a <= n <= b:
print "yes"
else:
print "no"
use the replace >= and <= with > and < to check whether n is in the exclusive range denoted by a and b (i.e. a and b are not themselves members of the range).
Range will produce an arithmetic progression defined by the two (or three) arguments converted to integers. See the documentation. This is not what you want I guess.
To check whether some number n is in the inclusive range denoted by the two number a and b you do either
use the replace
>=
and<=
with>
and<
to check whethern
is in the exclusive range denoted bya
andb
(i.e.a
andb
are not themselves members of the range).Range will produce an arithmetic progression defined by the two (or three) arguments converted to integers. See the documentation. This is not what you want I guess.
No, you can't do that.
range()
expects integer arguments. If you want to know ifx
is inside this range try some form of this:Be careful with your upper limit. If you use
range()
it is excluded (range(0, 5)
does not include 5!)Old faithful:
And it doesn't look like Perl (joke)
I would use the numpy library, which would allow you to do this for a list of numbers as well: