Path: csiph.com!usenet.pasdenom.info!news.franciliens.net!news.muarf.org!nntpfeed.proxad.net!proxad.net!feeder1-1.proxad.net!hq-usenetpeers.eweka.nl!hq-usenetpeers.eweka.nl!bcyclone02.am1.xlned.com!bcyclone02.am1.xlned.com!newsfeed.xs4all.nl!newsfeed2a.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; 'context': 0.07; 'expressions': 0.07; 'none,': 0.07; 'alain': 0.09; 'false,': 0.09; 'false.': 0.09; 'interpreted': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'thus,': 0.09; 'python': 0.11; '2.7': 0.14; '"in': 0.16; 'boolean': 0.16; 'containers': 0.16; 'evaluating': 0.16; 'exactly,': 0.16; 'false:': 0.16; 'frozensets).': 0.16; 'interest,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'selects': 0.16; 'statements,': 0.16; 'true:': 0.16; 'tuples,': 0.16; 'types,': 0.16; 'unequal,': 0.16; 'wrote:': 0.18; 'rules': 0.22; 'header:User-Agent:1': 0.23; 'apply.': 0.24; '(see': 0.26; 'academic': 0.26; 'compare': 0.26; 'somewhere': 0.26; 'values': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; 'operations,': 0.30; 'sets': 0.30; 'statement': 0.30; 'received:132': 0.31; 'suites': 0.31; 'writes:': 0.31; '(including': 0.33; 'url:python': 0.33; '"the': 0.34; 'definition': 0.35; 'operations': 0.35; 'but': 0.35; 'there': 0.35; 'version': 0.36; 'false': 0.36; 'i.e.': 0.36; 'url:org': 0.36; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'flow': 0.39; 'to:addr:python.org': 0.39; 'changed': 0.39; 'received:org': 0.40; 'expression': 0.60; 'first': 0.61; 'evaluate': 0.72; 'kennedy': 0.84; 'manual,': 0.84; 'url:reference': 0.84; 'hand,': 0.93 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Wolfgang Maier Subject: Re: Truthiness Date: Thu, 23 Oct 2014 17:01:43 +0200 References: <61f0b04c-b827-4c03-b55d-4d5bd85b56f6@googlegroups.com> <87bnp23ksg.fsf@dpt-info.u-strasbg.fr> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: px1.ruf.uni-freiburg.de User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.2.0 In-Reply-To: <87bnp23ksg.fsf@dpt-info.u-strasbg.fr> 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: 49 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1414076484 news.xs4all.nl 2878 [2001:888:2000:d::a6]:42638 X-Complaints-To: abuse@xs4all.nl X-Received-Body-CRC: 2487875557 X-Received-Bytes: 4800 Xref: csiph.com comp.lang.python:79534 On 10/23/2014 04:47 PM, Alain Ketterlin wrote: > Simon Kennedy writes: > >> Just out of academic interest, is there somewhere in the Python docs where the following is explained? >> >>>>> 3 == True >> False >>>>> if 3: >> print("It's Twue") >> >> It's Twue >> >> i.e. in the if statement 3 is True but not in the first > > https://docs.python.org/2/reference/compound_stmts.html#the-if-statement > > says: "The if statement [...] selects exactly one of the suites by > evaluating the expressions one by one until one is found to be true (see > section Boolean operations for the definition of true and false)" > Exactly, but in if 3 == True: the expression is 3==True , in which 3 and True compare unequal, thus, the expression is false. On the other hand, in if 3: the expression to evaluate is just the int object and the rules below apply. > and then: > > https://docs.python.org/2/reference/expressions.html#booleans > > says: "In the context of Boolean operations, and also when expressions > are used by control flow statements, the following values are > interpreted as false: False, None, numeric zero of all types, and empty > strings and containers (including strings, tuples, lists, dictionaries, > sets and frozensets). All other values are interpreted as true." > > (links are to the 2.7 version of the reference manual, I think not much > has changed in 3.* versions.) > > -- Alain. >