Check if a given value is out of certain range

sohcahtoa82 at gmail.com sohcahtoa82 at gmail.com
Wed Sep 30 20:31:21 CEST 2015


On Tuesday, September 29, 2015 at 1:33:23 PM UTC-7, Mark Lawrence wrote:
> On 29/09/2015 17:48, Rob Gaddi wrote:
> > On Tue, 29 Sep 2015 10:16:04 +0530, Laxmikant Chitare wrote:
> >
> >> Hi,
> >>
> >> I know there is an elegant way to check if a given value is within
> >> certain range.
> >> Example - To check if x is between zero and ten, I can do 0 < x 10.
> >>
> >> Is there any similar elegant way to check if a value is out of certain
> >> range?
> >> Example - To check if x is either less than zero or greater than ten?
> >> Right now I am using x < 0 or x > 10.
> >>
> >> Regards,
> >> Laxmikant
> >
> > not (0 <= x <= 10)
> >
> 
> Yuck.
> 
> -- 
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
> 
> Mark Lawrence

What is so "yuck" about that?  What would you do instead?  It seems like the best solution to me.  Easy to read, fast to execute.


More information about the Python-list mailing list