Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4.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.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'guys!': 0.09; 'parsing': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; '"and"': 0.16; '"or"': 0.16; '*only*': 0.16; 'ah...': 0.16; 'boolean': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'rule.': 0.16; '>>>': 0.22; 'tend': 0.24; 'url:home': 0.24; 'mon,': 0.24; 'header:X-Complaints-To:1': 0.27; 'evaluation': 0.30; 'code': 0.31; 'covered': 0.32; 'but': 0.35; 'charset:us- ascii': 0.36; 'two': 0.37; 'received:76': 0.38; 'thank': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'days': 0.60; 'valuable': 0.63; '2013': 0.98 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Dennis Lee Bieber Subject: Re: Short-circuit Logic Date: Mon, 27 May 2013 21:36:30 -0400 Organization: > Bestiaria Support Staff < References: <5f101d70-e51f-4531-9153-c92ee2486fd9@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: adsl-76-253-110-232.dsl.klmzmi.sbcglobal.net X-Newsreader: Forte Agent 3.3/32.846 X-No-Archive: YES 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: 46 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1369704999 news.xs4all.nl 15889 [2001:888:2000:d::a6]:37300 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:46245 On Mon, 27 May 2013 13:08:34 -0700 (PDT), Ahmed Abdulshafy declaimed the following in gmane.comp.python.general: > Thank you guys! you gave me valuable insights! But regarding my original post, I don't know why for the past two days I was looking at the code *only* this way> > if ( not allow_zero and abs(x) ) < sys.float_info.epsilon: > Ah... That's covered under "operator precedence" and not the short-circuit evaluation rule. Boolean "and" and "or" tend to come last in the parsing (bitwise & and ^ come earlier, as I recall) {Python 2.x} >>> 5 & 2 0 >>> 5 ^ 2 7 >>> 5 and 2 2 >>> 5 or 2 5 >>> >>> 5 & 2 and 5 ^ 2 0 >>> 5 & 2 or 5 ^ 2 7 >>> 5 ^ 2 and 5 & 2 0 >>> 5 ^ 2 or 5 & 2 7 >>> >>> 5 ^ (2 or 5) & 2 7 >>> 5 ^ (2 and 5) & 2 5 >>> 5 & (2 and 5) ^ 2 7 >>> 5 & (2 or 5) ^ 2 2 >>> -- Wulfraed Dennis Lee Bieber AF6VN wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/