Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Erik Newsgroups: comp.lang.python Subject: Re: Operator Precedence/Boolean Logic Date: Wed, 22 Jun 2016 20:43:46 +0100 Lines: 25 Message-ID: References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> <576AEA72.1040904@lucidity.plus.com> Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de rUdWT6Gsrytl4SEaOr47LQx3O5aPeQAxbVyl0QHKdOqQ== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'none,': 0.05; 'false.': 0.07; 'true)': 0.07; 'dict': 0.09; 'tuple': 0.09; '"in"': 0.16; '(false,': 0.16; 'evaluates': 0.16; 'false:': 0.16; 'from:addr:python': 0.16; 'match:': 0.16; 'operands': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'set,': 0.16; 'true:': 0.16; 'tuple,': 0.16; 'wrote:': 0.16; '>>>': 0.20; 'to:2**1': 0.21; 'trying': 0.22; "python's": 0.23; 'header:In- Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'dictionary': 0.29; 'subject:/': 0.30; 'becomes': 0.30; 'equal': 0.34; 'list': 0.34; 'false': 0.35; 'keyword': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'things': 0.38; 'why': 0.39; 'does': 0.39; 'received:192': 0.39; 'to:addr:python.org': 0.40; 'collection': 0.60; 'your': 0.60; 'side': 0.62; 'charset:windows-1252': 0.62; 'course': 0.62; 'elizabeth': 0.72; 'hand': 0.82; '(is': 0.84; 'construct': 0.84 X-CM-Score: 0.00 X-CNFS-Analysis: v=2.2 cv=J7fo10vS c=1 sm=1 tr=0 a=pxoLDhAR/7Lknl+8opcxAA==:117 a=pxoLDhAR/7Lknl+8opcxAA==:17 a=N659UExz7-8A:10 a=IHsFpIF1StDgeeHSR2sA:9 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.8.0 In-Reply-To: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <576AEA72.1040904@lucidity.plus.com> X-Mailman-Original-References: <15997174-44d5-431c-8f90-a8d700921820@googlegroups.com> Xref: csiph.com comp.lang.python:110335 On 22/06/16 04:40, Elizabeth Weiss wrote: > I am a little confused as to how this is False: > > False==(False or True) Other people have explained why the expression evaluates as it does - the sub-expression "False or True" evaluates to True (as one of the operands is truthy). Your expression then becomes "False == True", which is of course false. To get the construct you were expecting (is the thing on the left hand side equal to one of the things on the right hand side), you can use Python's "in" keyword to "search" a collection (list, tuple, set, dictionary etc) that contains the things you are trying to match: >>> False in (False, True) # tuple >>> False in [False, True] # list >>> False in {False, True} # set >>> False in {False: None, True: None} # dict HTH, E.