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


Groups > comp.lang.python > #108137

Re: Conditionals And Control Flows

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Subject Re: Conditionals And Control Flows
Date Thu, 5 May 2016 00:58:25 +1000
Lines 44
Message-ID <mailman.387.1462373907.32212.python-list@python.org> (permalink)
References <f12b6c42-8edb-4f91-8994-7c122e99461e@googlegroups.com> <CAPTjJmpcKKaQzaTuC4xQG=QDSPq+WyjMtkEBrycSk3K_GwaS7A@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de ure04zgART9wrFVMR8ifKguo1ZJM78Ys5wLayN+7+f0Q==
Return-Path <rosuav@gmail.com>
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; 'data:': 0.07; 'interpreter.': 0.07; 'true)': 0.07; 'works.': 0.07; 'cc:addr:python-list': 0.09; 'false)': 0.09; 'get.': 0.09; 'messing': 0.09; 'statements': 0.09; 'python': 0.10; 'python.': 0.11; 'thu,': 0.15; '"and"': 0.16; '2016': 0.16; 'boolean': 0.16; 'conditional': 0.16; 'expressions,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'instance,': 0.18; 'stick': 0.18; '>>>': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'handles': 0.20; 'trying': 0.22; 'am,': 0.23; '(or': 0.23; "python's": 0.23; 'header:In-Reply-To:1': 0.24; "doesn't": 0.26; 'message-id:@mail.gmail.com': 0.27; 'correct': 0.28; 'values': 0.28; '---': 0.28; 'windows,': 0.29; 'received:209.85.215.46': 0.30; 'supposed': 0.31; "can't": 0.32; 'statement': 0.32; 'open': 0.33; 'received:google.com': 0.35; 'so,': 0.35; 'on,': 0.35; 'easiest': 0.35; 'false': 0.35; 'platforms,': 0.35; 'but': 0.36; 'should': 0.36; 'received:209.85': 0.36; 'subject:: ': 0.37; 'received:209': 0.38; 'test': 0.39; 'build': 0.40; 'some': 0.40; 'ever': 0.60; 'your': 0.60; 'more': 0.63; "'and'": 0.84; 'chrisa': 0.84; 'subject:Control': 0.84; 'to:none': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc; bh=C9Ua33ANVj2AS+6/idPM4Bs2pNUzRobJG6ypa0MvqeE=; b=KoMkyjRJr2FgXT3sukaJXiRF3LmT0WF12RN+xkNG8RckK3jhzdiDI0q+nCFb/t2nYY 0eu+MvIkCu66jlQ0vLNulBMDFMYSV+84Cvv/KowWYGvZizbjG9q1PAB9FU3TFH8rEC3u TwePBGtWvhPBgbRg1eX0GBbxl9VlXIeJu8HjCW1asDXS6kZnjrJy2nM948szUSJ+zPRn Hc92Em6ynxdxgpCk2jNmthkHRfQ/0StMv/4qpGiDMj4G0bt1Tqc+bg3e9ZLRCRyENKqK lOVfQrvKt7XK09SZgJZkXz2fqpmDcQFDmRemOSV+ZilJmUuSmlW35DxzTglf/W4e6cFC PgAw==
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc; bh=C9Ua33ANVj2AS+6/idPM4Bs2pNUzRobJG6ypa0MvqeE=; b=KE/iVSKpwVJRdmNwrIxDFruMg8zSE195hhAf2yW3vJf+PgpcBIo6r70rKo81Oe48+Q 9b4nRWfo3UEAgiH7PdRXYSNHzMGc9aKielaQFkiZB8oESLvo4OnPrJP6TggvhTu8JSVQ 6PjTcti0jsxiHMbDUrGFGBue3NQZL1uuJaBWLqxc9Co/h5uCKwSArCKfVTyAyLPE3fUv N5k2v4IuNoyEvohwY7vh7dYbKL8eH7jhrcY3DHIoW/iWZGX32f3UZb0XgWCjJ/3oKSyH whDT/HiVOrRn4FR+zI8HakQnlXdROQIKNsx8yrGWMkuhPgDhi2XLZ7mVc3+qDZAo54qn sdKw==
X-Gm-Message-State AOPr4FVGIpMIUHeKxpb8N1jN/GRgjRZpZNpE+2VbSefpHdyiIQ+V4zLP7BVCVoijoNTT0N2Xw8QUNU/aH5FKuA==
X-Received by 10.112.198.72 with SMTP id ja8mr4240423lbc.112.1462373906075; Wed, 04 May 2016 07:58:26 -0700 (PDT)
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 <CAPTjJmpcKKaQzaTuC4xQG=QDSPq+WyjMtkEBrycSk3K_GwaS7A@mail.gmail.com>
X-Mailman-Original-References <f12b6c42-8edb-4f91-8994-7c122e99461e@googlegroups.com>
Xref csiph.com comp.lang.python:108137

Show key headers only | View raw


On Thu, May 5, 2016 at 12:41 AM, Cai Gengyang <gengyangcai@gmail.com> 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
>
> For instance,
>
> 1 < 3 and 10 < 20 is True --- (because both statements are true)
> 1 < 5 and 5 > 12 is False --- (because both statements are false)
>
> bool_one = False and False --- This should give False because none of the statements are False
> bool_two = True and False --- This should give False because only 1 statement is True
> bool_three = False and True --- This should give False because only 1 statement is True
> bool_five = True and True --- This should give True because only 1 statement is True
>
> Am I correct ?

Not entirely so, but very close. So long as you stick to the exact
values True and False (or simple conditional expressions, like your
examples), yes, that's what you'd get.

The best way to try these out is the interactive interpreter. On
Windows, look in your Start menu for "IDLE"; on other platforms, open
up a terminal and type "python3". Then just start messing around:

>>> 1 < 3 and 10 < 20
True
>>> 1 < 5 and 5 > 12
False

This is far and away the easiest way to learn how Python works. You
can even play with some other things, and learn how Python's 'and'
operator handles other types of data:

>>> 1 and 4
4
>>> 0 and 3
0

Confused? Keep messing around. Build up a theory as to what's going
on, test your theory, then go check your theory against the
documentation. (Or come and ask here, if you can't find it in the
docs.) Python doesn't mind how much you poke around with it, and you
will learn ever so much more than we can explain!

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next 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