Path: csiph.com!goblin2!goblin1!goblin.stu.neva.ru!uio.no!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!nzpost1.xs4all.net!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.037 X-Spam-Evidence: '*H*': 0.93; '*S*': 0.01; 'else:': 0.03; 'correct.': 0.07; 'elegant': 0.07; '"not"': 0.16; '-tkc': 0.16; 'clauses': 0.16; 'from:addr:python.list': 0.16; 'from:addr:tim.thechases.com': 0.16; 'from:name:tim chase': 0.16; 'wrote:': 0.16; 'lawrence': 0.22; 'header:In-Reply-To:1': 0.24; 'example': 0.26; 'read,': 0.29; 'there.': 0.30; 'certain': 0.31; 'similar': 0.33; 'there': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'charset:us-ascii': 0.37; 'things': 0.38; 'sure': 0.39; 'to:addr:python.org': 0.40; 'mark': 0.40; 'easy': 0.60; 'received:10.235': 0.84; 'received:162.253': 0.84; 'subject:value': 0.84; 'improvement': 0.93; 'subject:Check': 0.95 X-Sender-Id: wwwh|x-authuser|tim@thechases.com X-Sender-Id: wwwh|x-authuser|tim@thechases.com X-MC-Relay: Neutral X-MailChannels-SenderId: wwwh|x-authuser|tim@thechases.com X-MailChannels-Auth-Id: wwwh X-MC-Loop-Signature: 1443570327128:776799155 X-MC-Ingress-Time: 1443570327128 Date: Tue, 29 Sep 2015 18:44:33 -0500 From: Tim Chase To: python-list@python.org Subject: Re: Check if a given value is out of certain range In-Reply-To: References: X-Mailer: Claws Mail 3.11.1 (GTK+ 2.24.25; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-AuthUser: tim@thechases.com X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 25 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1443578914 news.xs4all.nl 23800 [2001:888:2000:d::a6]:55075 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:97224 On 2015-09-29 21:32, Mark Lawrence wrote: > On 29/09/2015 17:48, Rob Gaddi wrote: > >> 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. > > > > not (0 <= x <= 10) > > Yuck. Not sure there's much "yuck" to be had there. It's succinct, easy to read, and correct. The only improvement might be if you have things to do in both cases, in which case remove the "not" and set the clauses accordingly: if 0 <= x <= 10: success_within_range(x) else: fail_out_of_bounds(x) -tkc