Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed2.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.045 X-Spam-Evidence: '*H*': 0.91; '*S*': 0.00; 'python.': 0.02; 'charset:iso-8859-7': 0.04; 'string': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'before.': 0.16; 'nick': 0.16; 'year)': 0.16; '(where': 0.19; 'value.': 0.19; 'seems': 0.21; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'least': 0.26; 'header:In-Reply-To:1': 0.27; 'michael': 0.29; 'am,': 0.29; 'received:209.85.217': 0.29; 'specified': 0.30; 'especially': 0.30; 'message-id:@mail.gmail.com': 0.30; 'url:wiki': 0.31; '>>>>': 0.31; 'terms.': 0.31; 'url:wikipedia': 0.31; 'this.': 0.32; 'fri,': 0.33; 'not.': 0.33; 'basic': 0.35; 'received:209.85': 0.35; 'one,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'google': 0.35; '14,': 0.36; 'returning': 0.36; 'doing': 0.36; 'url:org': 0.36; 'too': 0.37; 'received:209': 0.37; 'that,': 0.38; 'how': 0.40; 'expression': 0.60; 'first': 0.61; 'show': 0.63; 'within': 0.65; 'here': 0.66; 'behavior': 0.77; 'ending': 0.78; "'and'": 0.84; 'subject:gets': 0.84; 'to:addr:support': 0.84; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=kbASc3aDPF5o2mEmbeKYPcHHNHo751dYq07NXGx0lFE=; b=fAVQGA74Xyk8arPZlgADd7tzAw9aRkAnXzNLKC7D4C+3RIB3VLkozCxLdlTGFbceMr gAJyILyJRX594BQTxjCAWx5g2jL2z0uFxPwHwkcl9wyXzDntnOsGTMiSISmyqb6d75X9 oUosQCPt/c3Hk16eiuHAcp1HPxDohWJEI9jW/11405aTzbS0GR6OBiwdP8hXPhRVseqe V4hyRqOYDDpXbEu/fot+q7RqlnTLlUkJpqZglq3hC/eVM/MQKUznbrPAbYTo78xOD1JE n23LoADkhtnXHo/cadxmHiubsWJcHcF7T0cORyyNWBySrVA8M8D3xkmpfuR80iRxQSrv vJCg== X-Received: by 10.152.25.135 with SMTP id c7mr619927lag.39.1371198278938; Fri, 14 Jun 2013 01:24:38 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <2bc90d3b-09c2-4315-9357-ff7f039465e0@googlegroups.com> <51b926a3$0$29997$c3e8da3$5496439d@news.astraweb.com> <51ba6e92$0$29997$c3e8da3$5496439d@news.astraweb.com> From: "R. Michael Weylandt" Date: Fri, 14 Jun 2013 09:24:18 +0100 Subject: Re: A certainl part of an if() structure never gets executed. To: Nick the Gr33k Content-Type: text/plain; charset=ISO-8859-7 Cc: python-list 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: 37 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1371198287 news.xs4all.nl 15940 [2001:888:2000:d::a6]:57596 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:48084 On Fri, Jun 14, 2013 at 9:03 AM, Nick the Gr33k wrote:> >>>> name="abcd" >>>> month="efgh" >>>> year="ijkl" > >>>> print(name or month or year) > abcd > > Can understand that, it takes the first string out of the 3 strings that has > a truthy value. > >>>> print("k" in (name and month and year)) > True > > No clue. since the expression in parenthesis returns 'abcd' how can 'k' > contained within 'abcd' ? No it's not. See both above (where you use 'or' instead) and below where _you yourself_ show that it's not 'abcd.' Now read: https://en.wikipedia.org/wiki/Short-circuit_evaluation noting especially the specified behavior for Python. If you find it too technical, google for other uses of the terms. > >>>> print(name and month and year) > ijkl > > Seems here is returning the last string out of 3 strings, but have no clue > why Python doing this. Think about basic logic: 'or' means 'is at least one true?' so Python only has to look at the first 'truthy value'. 'and' means 'are they all true?' so Python has to look at all the values, ending up with the last one, unless a 'falsey value' is found before. Michael