Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.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; 'subject:" ': 0.03; 'operator': 0.05; 'python': 0.08; '>>>>': 0.09; 'caller.': 0.09; 'compute': 0.09; 'context.': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; 'received:gator410.hostgator.com': 0.09; 'return,': 0.09; '~ethan~': 0.09; '25,': 0.12; 'am,': 0.13; 'wrote:': 0.15; 'billy': 0.16; 'bitwise': 0.16; 'boolean': 0.16; 'computation': 0.16; 'object)': 0.16; 'or.': 0.16; 'received:72.11': 0.16; 'received:72.11.125': 0.16; 'received:72.11.125.166': 0.16; 'returned,': 0.16; 'pm,': 0.16; '>>>': 0.16; 'header:In-Reply- To:1': 0.22; 'collins': 0.23; 'statement': 0.25; 'function': 0.26; 'values': 0.31; 'expression': 0.32; 'used,': 0.32; 'does': 0.32; 'together.': 0.33; 'actually': 0.33; 'to:addr:python-list': 0.34; 'header:User-Agent:1': 0.34; 'none': 0.35; 'actual': 0.35; 'supposed': 0.35; 'unless': 0.37; 'but': 0.37; 'takes': 0.38; 'subject:: ': 0.38; 'case': 0.39; 'returned': 0.39; 'to:addr:python.org': 0.39; 'hope': 0.60; 'received:websitewelcome.com': 0.65; 'received:184': 0.67; 'received:69.93': 0.67; 'evaluate': 0.71; '10:16': 0.84; '-->': 0.91; 'received:gateway02.websitewelcome.com': 0.93 Date: Mon, 25 Jul 2011 13:07:08 -0700 From: Ethan Furman User-Agent: Thunderbird 1.5.0.10 (Windows/20070221) MIME-Version: 1.0 To: python-list@python.org Subject: Re: Pipe in the "return" statement References: <9954ddFkjuU10@mid.individual.net> <1c175da2-79f4-40ed-803f-217dc935df6c@m8g2000yqo.googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator410.hostgator.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - stoneleaf.us X-BWhitelist: no X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: mail.admailinc.com ([192.168.10.136]) [72.11.125.166]:2746 X-Source-Auth: ethan+stoneleaf.us X-Email-Count: 2 X-Source-Cap: dG9idWs7dG9idWs7Z2F0b3I0MTAuaG9zdGdhdG9yLmNvbQ== 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: 47 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1311623510 news.xs4all.nl 23952 [2001:888:2000:d::a6]:53039 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:10305 Billy Mays wrote: > On 07/25/2011 10:16 AM, Archard Lias wrote: >> On Jul 25, 2:03 pm, Ian Collins wrote: >>> On 07/26/11 12:00 AM, Archard Lias wrote: >>>> Still I dont get how I am supposed to understand the pipe and its task/ >>>> idea/influece on control flow, of: >>>> return | >>>> ?? >>> >>> It's simply a bitwise OR. >> >> Yes, but how does it get determined, which one actually gets returned? > > The return statement returns a single value from a function context. The > pipe operator takes 2 values and bitwise ORs* them together. That > result is then returned to the caller. Just for completeness, if the actual line had been return or then Python would compute , and if its boolean value was True would return the computation of , otherwise it would compute and return that. When 'or' is used, the first truthy* item is return, or the last falsey* item if none evaluate to True. --> None or 2 or 0 2 --> None or 2 or 3 2 --> None or [] or 0 0 With 'and', the first falsey item is returned, unless all the items are truthy in which case the last item is returned: --> 2 and 3 3 --> 2 and 0 and 9 0 Hope this helps. ~Ethan~ * 'truthy' = bool(some expression or object) == True * 'falsey' = bool(some expression or object) == False