Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python.': 0.02; 'subject:not': 0.03; 'interpreter': 0.05; '(using': 0.07; 'none:': 0.07; 'subject:two': 0.07; 'variables': 0.07; 'correspond': 0.09; 'subject:None': 0.09; 'way:': 0.09; 'cc:addr:python-list': 0.11; 'chained': 0.16; 'contest.': 0.16; 'fluent': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'mean,': 0.16; 'roy': 0.16; 'sense:': 0.16; 'two,': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'variable': 0.18; 'written': 0.21; '>>>': 0.22; 'coding': 0.22; 'cc:addr:python.org': 0.22; 'certainly': 0.24; 'parse': 0.24; 'cc:2**0': 0.24; 'suggested': 0.26; 'post': 0.26; 'least': 0.26; 'header:In-Reply-To:1': 0.27; 'points': 0.29; 'message-id:@mail.gmail.com': 0.30; 'constant': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'way?': 0.31; 'figure': 0.32; 'checking': 0.33; 'agree': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'belong': 0.36; 'useful': 0.36; 'thanks': 0.36; 'wrong': 0.37; 'two': 0.37; 'clear': 0.37; 'being': 0.38; 'sometimes': 0.38; 'checks': 0.38; 'conditions.': 0.38; 'fact': 0.38; 'pm,': 0.38; 'that,': 0.38; 'does': 0.39; 'how': 0.40; 'even': 0.60; "you're": 0.61; 'more': 0.64; '30,': 0.65; 'mar': 0.68; 'night,': 0.68; 'smith': 0.68; 'apart': 0.72; "it'd": 0.84; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=9qx9WITTIeF6viEjWYmPZN8Du5ltfK115tsQe2xveSY=; b=ZuO+A4DRR4pJHKfh7ICNWQLVfrV06MIRAOyFNhcPDuT0OEdj75zUM6oYWX9PBaodcb ZBbx8w92kMQSlnP13xIBKbJWvAjEMgQfpZilKuBsgdsU5GqHX4zSVimiCK762fIhJ8DG hB8+KUnvL74ktnYVUsU07HlM/puX5N2TTPfuFd8vJzBG+Wb7KPDLn1FhGasrQ8UtItMV 4oZe8hr7dZ1FsAty0k/TSswUUQTFVxeHwMPg7cy6h3C8uD+wVxknzjnzooqkOCplpaNy CRHQrQamQb3wc9UAPlyLji8jIvosXye+IUF8VLaI4JSlHzfbFjmLvZyDMyix2kwyX8ko 0JTw== MIME-Version: 1.0 X-Received: by 10.68.201.97 with SMTP id jz1mr17008660pbc.26.1396145718257; Sat, 29 Mar 2014 19:15:18 -0700 (PDT) In-Reply-To: <53377b9e$0$29994$c3e8da3$5496439d@news.astraweb.com> References: <0245aca0-c6b7-493a-aa52-2c3ef6462dbd@googlegroups.com> <5337195f$0$29994$c3e8da3$5496439d@news.astraweb.com> <53377b9e$0$29994$c3e8da3$5496439d@news.astraweb.com> Date: Sun, 30 Mar 2014 13:15:18 +1100 Subject: Re: checking if two things do not equal None From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 41 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1396145720 news.xs4all.nl 2831 [2001:888:2000:d::a6]:47132 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:69361 On Sun, Mar 30, 2014 at 1:04 PM, Steven D'Aprano wrote: > On Sat, 29 Mar 2014 17:07:20 -0400, Roy Smith wrote: > >> I certainly agree that things like >> >>> if a is not b is not None: ... >> >> belong in an obfuscated coding contest. > > Apart from the fact that I got it wrong (that's what happens when I post > at 6am after being up all night, thanks for the correction Lele), if you > consider chained comparisons to be "obfuscated", I think you're not > really fluent at Python. The OP even suggested `a != None != b` so I > think that (s)he at least understands chained comparisons. > > However, I agree with Johannes that inverted conditions (using "not") are > sometimes harder to reason about than "regular" conditions. Chained comparisons where you're checking a single variable against two constants make perfect sense: 2 < x < 5 Chained comparisons where you check a single constant against two variables don't, so much: x < 2 < y What exactly does that mean, and why is it written that way? We can figure out how the interpreter will parse that, but does that correspond to the programmer's intention? It'd be more useful but less clear if one of the conditions points the other way: x < 2 > y which checks that they're both less than two, but IMO in a less-than-clear way. ChrisA