Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #108148

Re: Conditionals And Control Flows

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Stephen Hansen <me+python@ixokai.io>
Newsgroups comp.lang.python
Subject Re: Conditionals And Control Flows
Date Wed, 04 May 2016 11:54:29 -0700
Lines 32
Message-ID <mailman.389.1462388072.32212.python-list@python.org> (permalink)
References <f12b6c42-8edb-4f91-8994-7c122e99461e@googlegroups.com> <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 <me+python@ixokai.io>
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 <f12b6c42-8edb-4f91-8994-7c122e99461e@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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <1462388069.1988878.598232289.669D262F@webmail.messagingengine.com>
X-Mailman-Original-References <f12b6c42-8edb-4f91-8994-7c122e99461e@googlegroups.com>
Xref csiph.com comp.lang.python:108148

Show key headers only | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Conditionals And Control Flows Cai Gengyang <gengyangcai@gmail.com> - 2016-05-04 07:41 -0700
  Re: Conditionals And Control Flows Bob Gailer <bgailer@gmail.com> - 2016-05-04 10:54 -0400
  Re: Conditionals And Control Flows Michael Selik <michael.selik@gmail.com> - 2016-05-04 14:56 +0000
  Re: Conditionals And Control Flows Chris Angelico <rosuav@gmail.com> - 2016-05-05 00:58 +1000
  Re: Conditionals And Control Flows Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-05-04 18:10 +0300
    Re: Conditionals And Control Flows Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-05-04 16:21 +0100
    Re: Conditionals And Control Flows Cai Gengyang <gengyangcai@gmail.com> - 2016-05-04 08:23 -0700
      Re: Conditionals And Control Flows Jussi Piitulainen <jussi.piitulainen@helsinki.fi> - 2016-05-04 19:41 +0300
  Re: Conditionals And Control Flows Stephen Hansen <me+python@ixokai.io> - 2016-05-04 11:54 -0700

csiph-web