Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Stephen Hansen Newsgroups: comp.lang.python Subject: Re: Conditionals And Control Flows Date: Wed, 04 May 2016 11:54:29 -0700 Lines: 32 Message-ID: References: <1462388069.1988878.598232289.669D262F@webmail.messagingengine.com> Mime-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de /2r835BAcUrSzoKTVGSvYwzK5QYb3o9kVuCvEm1cCywA== 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; 'operator': 0.03; 'true,': 0.04; 'none,': 0.05; '(of': 0.07; 'defines': 0.07; 'false,': 0.07; 'false.': 0.07; '0),': 0.09; 'logic': 0.09; 'received:internal': 0.09; 'python': 0.10; 'python.': 0.11; 'wed,': 0.15; '"and"': 0.16; 'boolean': 0.16; 'mappings,': 0.16; 'message- id:@webmail.messagingengine.com': 0.16; 'operator.': 0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16; 'received:66.111': 0.16; 'received:66.111.4': 0.16; 'received:io': 0.16; 'received:messagingengine.com': 0.16; 'received:psf.io': 0.16; 'type),': 0.16; 'wrote:': 0.16; 'case.': 0.18; 'saying': 0.22; 'stephen': 0.22; 'trying': 0.22; 'am,': 0.23; 'header:In- Reply-To:1': 0.24; 'define': 0.27; 'operations,': 0.27; 'see,': 0.27; 'container': 0.29; 'classes': 0.30; 'that.': 0.30; 'supposed': 0.31; 'though,': 0.32; 'instances': 0.33; 'instead,': 0.33; 'rule': 0.33; 'case,': 0.34; 'false': 0.35; 'something': 0.35; 'but': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'things': 0.38; 'received:66': 0.38; 'to:addr:python.org': 0.40; 'still': 0.40; 'some': 0.40; 'ever': 0.60; 'header:Message-Id:1': 0.61; 'wanting': 0.66; 'decided': 0.66; "'and'": 0.84; 'subject:Control': 0.84; 'thing,': 0.93 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=ixokai.io; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=OT7jECvZh2VDBztZtOz2C2oZUIs=; b=cQ2aLa ZLVdSel2F4YnxYXZ1pCkhscYM2OpfyJzcy+z3tSZqB0NtKpR5rmKhYBL06RE1jKS RDiENLxqkF3LwRS9Is+WpcDFwKuxByxPrI0JtPjhHIk7upyr7KIxjhiyAUkgo54q 2mczUK3vOZn0fx8g76R4F0AJIqgXcJ1laFZqg= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=OT7jECvZh2VDBzt ZtOz2C2oZUIs=; b=Gr1B56YTmAfUynm6n9iTSyAPD/LlpyMkBu0okEUovR9m+NT M6k4zUv4ocsfFqOI6aiB3pgpCd44VCM7nsFG/WvGaYvIpH7bwa5F+HzE8NiX3ZIA LQ0+cQIgr2jkP5Xo+hdN1B0koqPH9+9mk3+Cp/BCIpN1OyU2oYQIer1l1vg0= X-Sasl-Enc: 37IflrVqkACAYzItFHdJZidrxJRMYLnOXy0OnThOr5Ad 1462388069 X-Mailer: MessagingEngine.com Webmail Interface - ajax-2227b085 In-Reply-To: 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: <1462388069.1988878.598232289.669D262F@webmail.messagingengine.com> X-Mailman-Original-References: Xref: csiph.com comp.lang.python:108148 On Wed, May 4, 2016, at 07:41 AM, Cai Gengyang wrote: > I am trying to understand the boolean operator "and" in Python. It is > supposed to return "True" when the expression on both sides of "and" are > true The thing is, its kinda dubious to think of 'and' as a 'boolean operator', because once you go down that road, some people start wanting it to be a *pure* boolean operator. Something that always returns True or False. Instead, 'and' and 'or' return something that is true, or something that is false. Notice the lower case. (I know the docs call them Boolean Operations, but I still think saying 'boolean' is unhelpful) Python defines false things as False, None, 0 (of any numeric type), an empty container (lists, tuples, mappings, something else that defines __len__ and it returns 0), and instances of classes that define __nonzero__ that return 0 or False. Everything else is a true thing. If you see "x and y", the rule is: if x is a false thing, it'll return something false. As it happens, it has x handy, and since its decided x is false, it'll return that. Therefore, "x and y" is false. If x is true, though, it'll return y. In this case, "x and y" will be a true thing if y is a true thing, and a false thing if y is a false thing. As you can see, all of this logic happens without ever using True or False. -- Stephen Hansen m e @ i x o k a i . i o