Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed1a.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.013 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'though:': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'true)': 0.09; 'python': 0.11; 'def': 0.12; 'literal.': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'wrote:': 0.18; 'not,': 0.20; '>>>': 0.22; 'header:User- Agent:1': 0.23; "i've": 0.25; 'header:X-Complaints-To:1': 0.27; 'evaluation': 0.30; 'once,': 0.31; 'sep': 0.31; 'writes:': 0.31; 'but': 0.35; 'really': 0.36; 'false': 0.36; 'needed': 0.38; 'to:addr:python-list': 0.38; 'fact': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'easy': 0.60; 'chain': 0.60; 'expression': 0.60; 'matter': 0.61; 'such': 0.63; 'more': 0.64; 'here': 0.66; '2013,': 0.91; 'subject:True': 0.91 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: 1 > 0 == True -> False Date: Thu, 30 Jan 2014 13:04:52 +0100 Organization: None References: <99b0aa22-5fb3-460a-a080-dacb1c0f2fda@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p5084a949.dip0.t-ipconnect.de User-Agent: KNode/4.7.3 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: 63 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1391083487 news.xs4all.nl 2968 [2001:888:2000:d::a6]:33455 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:64987 Jussi Piitulainen wrote: > Thibault Langlois writes: > >> Hello, >> >> $ python >> Python 2.7.4 (default, Sep 26 2013, 03:20:26) >> [GCC 4.7.3] on linux2 >> Type "help", "copyright", "credits" or "license" for more information. >> >>> 1 > 0 == True >> False >> >>> (1 > 0) == True >> True >> >>> 1 > (0 == True) >> True >> >>> >> >> What am I missing here ? > > One or both of the following: > > >>> 0 == True > False > >>> True and False > False > >>> 1 > 0 > True > > Or the fact that (1 > 0 == True) means ((1 > 0) and (0 == True)), > where each expression in such a chain is evaluated once, though in > this case it really does not matter since 0 is a literal. > > Hm, I don't know if the evaluation short-circuits. I think not, but > I've never needed to know, and I don't need to know now. It is easy to check though: >>> def zero(): ... print("zero") ... return 0 ... >>> def one(): ... print("one") ... return 1 ... >>> def true(): ... print("true") ... return True ... >>> one() > zero() == true() one zero true False >>> zero() > one() == true() zero one False So yes, evaluation does short-curcuit.