Path: csiph.com!usenet.pasdenom.info!goblin1!goblin2!goblin.stu.neva.ru!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'true,': 0.05; 'stops': 0.07; "subject:' ": 0.07; 'string': 0.09; 'false,': 0.09; 'second.': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'thread': 0.14; '"and"': 0.16; '"or"': 0.16; 'all).': 0.16; 'doing,': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'message- id:@cskk.homeip.net': 0.16; 'received:211.29': 0.16; 'received:211.29.132': 0.16; 'received:optusnet.com.au': 0.16; 'received:syd.optusnet.com.au': 0.16; 'simpson': 0.16; 'track.': 0.16; 'year)': 0.16; 'wrote:': 0.18; 'do.': 0.18; 'trying': 0.19; 'value.': 0.19; 'seems': 0.21; '>>>': 0.22; 'example': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'example.': 0.24; 'cheers,': 0.24; '(or': 0.24; 'cc:2**0': 0.24; 'cc:no real name:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'testing': 0.29; 'serve': 0.31; 'operations.': 0.31; 'this.': 0.32; 'another': 0.32; 'subject:with': 0.35; 'something': 0.35; 'test': 0.35; 'but': 0.35; 'received:com.au': 0.36; 'replies': 0.36; 'returning': 0.36; 'doing': 0.36; 'charset:us-ascii': 0.36; 'received:211': 0.38; 'that,': 0.38; 'bad': 0.39; 'how': 0.40; 'expression': 0.60; "you're": 0.61; 'first': 0.61; 'content- disposition:inline': 0.62; 'name': 0.63; 'more': 0.64; 'within': 0.65; 'here': 0.66; 'direct': 0.67; 'evaluate': 0.72; 'irrelevant': 0.84; 'to:addr:support': 0.84; 'imagine': 0.93 Date: Sat, 15 Jun 2013 10:14:03 +1000 From: Cameron Simpson To: Nick the Gr33k Subject: Re: Eval of expr with 'or' and 'and' within MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) References: X-Optus-CM-Score: 0 X-Optus-CM-Analysis: v=2.0 cv=eqSHVfVX c=1 sm=1 a=wom5GMh1gUkA:10 a=FBuLjTwyfbYA:10 a=kj9zAlcOel0A:10 a=vrnE16BAAAAA:8 a=ZtCCktOnAAAA:8 a=oXw8JkBlnBUA:10 a=aJPVkpOjO7d2gS0gXwkA:9 a=CjuIK1q_8ugA:10 a=ChdAjXE5lkUvdteQbhpnkQ==:117 Cc: python-list@python.org 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: 51 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1371257115 news.xs4all.nl 15994 [2001:888:2000:d::a6]:53281 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:48238 On 14Jun2013 12:50, Nikos as SuperHost Support wrote: | I started another thread because the last one was !@#$'ed up by | irrelevant replies and was difficult to jeep track. | | >>> 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' ? Did you print the result of "name and month and year"? It is the _last_ value (if true at all). You used "or" in the first example and "and" in the second. | >>> 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. To evaluate an "and" it must test all of them to be true, and it keeps the last value tested. (Or False, of course, if they are not all true, in which case Python stops testing at the first False). But for what you are doing, "and" and "or" are not good operations. Something like: "k" in (name+month+year) or "k" in name or "k" in month or "k" in year is a more direct and accurate way to write what I imagine you're trying to do. Cheers, -- Cameron Simpson No one is completely worthless... they can always serve as a bad example.