Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!news.mixmin.net!feed.xsnews.nl!border-3.ams.xsnews.nl!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'operator': 0.03; 'syntax': 0.03; 'preference': 0.05; 'say,': 0.05; 'expressions': 0.07; 'subject:code': 0.07; 'python': 0.09; 'augmented': 0.09; 'language': 0.14; '*only*': 0.16; 'evaluating': 0.16; 'expression,': 0.16; 'fine.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'syntaxerror:': 0.16; 'wrote:': 0.17; 'handles': 0.18; '>>>': 0.18; 'equivalent': 0.20; 'sort': 0.21; 'received:209.85.214.174': 0.21; '"",': 0.22; 'assignment': 0.22; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'message- id:@mail.gmail.com': 0.27; '(my': 0.29; 'comparison': 0.29; 'really,': 0.29; 'yes.': 0.29; 'expect': 0.31; 'code': 0.31; '(and': 0.32; 'file': 0.32; 'certain': 0.33; 'point,': 0.33; 'true.': 0.33; 'to:addr:python-list': 0.33; 'that,': 0.34; 'received:google.com': 0.34; 'received:209.85': 0.35; 'but': 0.36; 'programmers': 0.36; 'two': 0.37; 'quite': 0.37; 'rather': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'things': 0.38; 'nothing': 0.38; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'header:Received:5': 0.40; 'most': 0.61; 'thomas': 0.62; 'personal': 0.62; 'times': 0.63; 'more': 0.63; 'within': 0.64; 'jul': 0.65; 'special': 0.73; 'sole': 0.75; 'entities,': 0.84; 'expressive': 0.84; 'valid,': 0.84 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:to :content-type; bh=M+kAe0gcwvCeL2UzPdCELzC/rzcdT04pNI64fZb9b1o=; b=Xf89h1SoPbU61pAaPU0bNMQCSjQm6EZxAh3f2Tqd5lg9BOXwDyZZsxyA584EqfKFwi ZNjOVKJPQ3/ZwrpJYxdwLTGbxepgqhhsSK9TIpNo7r9eNRLL9s/MQloktfRnjebJI4rj cfU6K/fELktiYFQF1kwDh5PAxDRI9QzzfbUbmIqf30Zd1YWR6Ch8Atznt3/dLoWUpGpu lRdxLGfJuD8rx+YWIPO1mlUBssseD+dY0xu/UXxBa+jpB4S7KyEtWUV5rwc6zak91fZW i2bTadflHOT1mCmY3TRFYAzuoroNzubUiio8kAwUM/6rWqPwhcIWC9uXFp0vNTBwWslz v4dA== MIME-Version: 1.0 In-Reply-To: <4FEF7826.40900@jollybox.de> References: <6c39594f-79cb-4d4f-967e-bbc3f68cdbdf@f8g2000pbf.googlegroups.com> <4fed59b7$0$29978$c3e8da3$5496439d@news.astraweb.com> <2662370.TGmo96CKe1@PointedEars.de> <87wr2oecf6.fsf@dpt-info.u-strasbg.fr> <4FEF7117.7000109@jollybox.de> <4FEF7826.40900@jollybox.de> Date: Sun, 1 Jul 2012 09:25:30 +1000 Subject: Re: code review From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 54 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1341098734 news.xs4all.nl 6918 [2001:888:2000:d::a6]:40835 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:24710 On Sun, Jul 1, 2012 at 8:05 AM, Thomas Jollans wrote: > Yes. My sole point, really, is that "normally", one would expect these > two expressions to be equivalent: > > a < b < c > (a < b) < c > > This is clearly not true. Python has quite a few things like that, actually. The most noticeable for C programmers is: a = b = c = d = e = 0 which in C is identical to a = (b = (c = (d = (e = 0)))) because assignment is an expression, but in Python is equivalent to nothing because assignment is simply allowed to do multiple. Downside: *Only* simple assignment can be chained. Augmented assignment cannot: >>> a+=10 # That's fine. >>> a+=b+=10 File "", line 1 a+=b+=10 ^ SyntaxError: invalid syntax >>> a=b+=10 File "", line 1 a=b+=10 ^ SyntaxError: invalid syntax >>> a+=b=10 File "", line 1 a+=b=10 ^ SyntaxError: invalid syntax In C, these are all well-defined and valid, and are evaluated right-to-left, and do what you would expect. (And yes, it's handy at times to do this sort of thing.) So it's not a special case for the comparison operators; it's a more general case that Python handles certain chains of operators as single entities, rather than breaking everything down into "OPERAND OPERATOR OPERAND" and evaluating one at a time. Is it better than/worse than C? Not really. It's a design choice and we code within it. (My personal preference is for the C style, as it makes for a more expressive language with less mental glitching, but as I say, that's personal preference.) ChrisA