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


Groups > comp.lang.python > #110427

Re: Break and Continue: While Loops

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Subject Re: Break and Continue: While Loops
Date Fri, 24 Jun 2016 02:23:11 +1000
Lines 42
Message-ID <mailman.80.1466698995.11516.python-list@python.org> (permalink)
References <639b00e0-7b9d-4ed4-96ad-6afbcd536786@googlegroups.com> <nkgcrh$r90$1@dont-email.me> <CAPTjJmp=nAYjxQ-MnWAaXXEfWq3_FBBtbaugde72XPwydHNLqw@mail.gmail.com> <mailman.69.1466681968.11516.python-list@python.org> <nkh0jj$e4$1@dont-email.me> <CAPTjJmpFzcypEwECu3RAYysq3h8oNgPeDaKftdYYX4UeEabsgQ@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8
X-Trace news.uni-berlin.de 9RMRfq0RdEYBuqSwq9roVQVurksIxvuiVH55fBm7Gd5A==
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; 'true,': 0.04; 'false,': 0.07; 'false.': 0.07; 'cc:addr:python-list': 0.09; 'empty,': 0.09; 'object)': 0.09; 'python': 0.10; 'interpreter': 0.15; 'thu,': 0.15; '"none"': 0.16; '2016': 0.16; '23,': 0.16; '24,': 0.16; '[[]]': 0.16; 'empty.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'magic.': 0.16; 'operands': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'set,': 0.16; 'simple.': 0.16; 'wrote:': 0.16; 'string': 0.17; 'string,': 0.18; 'tells': 0.18; '>>>': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'interpret': 0.22; 'object.': 0.22; 'am,': 0.23; '(or': 0.23; 'represents': 0.23; 'header:In-Reply- To:1': 0.24; 'all.': 0.24; 'chris': 0.26; 'define': 0.27; 'fri,': 0.27; 'used,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'creating': 0.30; 'rules': 0.31; 'realize': 0.32; 'maybe': 0.33; 'class': 0.33; 'rule': 0.33; 'true.': 0.33; 'list': 0.34; 'received:google.com': 0.35; 'false': 0.35; 'instance': 0.35; 'something': 0.35; 'received:74.125.82': 0.35; 'asking': 0.35; 'sometimes': 0.35; 'but': 0.36; 'list,': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'itself': 0.38; 'anything': 0.38; 'mean': 0.38; 'represent': 0.38; 'where': 0.40; 'still': 0.40; 'some': 0.40; 'different': 0.63; 'results': 0.66; 'special': 0.73; 'chrisa': 0.84; 'etc,': 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:from:date:message-id:subject:cc; bh=tPBt4Fzwid4bSpXcGMenX0EUqondojn0L8OMSzu5dVI=; b=0/2rqPORMkdgNiidZ3aIzSCus/gJtaEjGL2aGbxlARLGufTwu3/GUDg2uPl7CFzhrF LvfYkXu9z109IpYgcJEkNBvIqTM6vetDDGnrZbkkXU8cBRYVxGVlGIIfD8lTzvXXiua0 xzhdMAs7xiTBQKG5tgiykG1MQ0wLq+d5gIyoYzhnZQtWirc8nPVY9pjF6kB3DDQBIz2j 895GutRQ61NDUT2havHmBlIPdz9PtoTO9/5BDhR8AvBUNOhqTocKZ1fxfl88hJS7gw8R AZT1mvv8TjZ41YkY+KXCM0GPcRGv79dF7s6iDLp0nvQ6GU3VbpIlxKvbIPMpU2Gc3zq8 psHg==
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:from:date :message-id:subject:cc; bh=tPBt4Fzwid4bSpXcGMenX0EUqondojn0L8OMSzu5dVI=; b=P5I3ePKLjLrHjX/XmOm8znh/Zh6ewKa2492b5QmhpWCJilw3PICrcE+26ysaX69P3C 0rTpk67U9N5W4DXaM8jB1qKYSQA5BrWjYOdKHy7WKF6nQRDjz3HpDCqb+PBeZiPQr4MQ He+0b41xYYwsdJ/NVfAtYK7ys7FUTsrxOyXVp2+xeHvhVLBMLaFMUCP7/kiMcF6zn6pJ oEJy4Dgkl98OHVqCeCX27sZ6YQgbQ2ggROQn8XICFZadBOS9uCKSwCzzmLFizDhvKH2W v5aGLIrvEViP5lrpvJMQ3Wm65vNIwe64nPqPKtxIPydGo05vZjG174iQ9S5tQy8ZclkP C3xA==
X-Gm-Message-State ALyK8tI/8rO72VVNOkNVRoMaWVjrD6j+B+h66EgqX5iO1BIdz20fZvBByeAusAtuFKP7QKBQEqnqpE4KNdRwhg==
X-Received by 10.28.130.132 with SMTP id e126mr1606507wmd.41.1466698992043; Thu, 23 Jun 2016 09:23:12 -0700 (PDT)
In-Reply-To <nkh0jj$e4$1@dont-email.me>
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 <CAPTjJmpFzcypEwECu3RAYysq3h8oNgPeDaKftdYYX4UeEabsgQ@mail.gmail.com>
X-Mailman-Original-References <639b00e0-7b9d-4ed4-96ad-6afbcd536786@googlegroups.com> <nkgcrh$r90$1@dont-email.me> <CAPTjJmp=nAYjxQ-MnWAaXXEfWq3_FBBtbaugde72XPwydHNLqw@mail.gmail.com> <mailman.69.1466681968.11516.python-list@python.org> <nkh0jj$e4$1@dont-email.me>
Xref csiph.com comp.lang.python:110427

Show key headers only | View raw


On Fri, Jun 24, 2016 at 1:52 AM, BartC <bc@freeuk.com> wrote:
> On 23/06/2016 12:39, Chris Angelico wrote:
>>
>> On Thu, Jun 23, 2016 at 8:15 PM, BartC <bc@freeuk.com> wrote:
>>>
>>> Actually pretty much any expression can be used, because Python can
>>> interpret almost anything as either True or False. Don't ask for the
>>> rules
>>> because they can be complicated, but for example, zero is False, and any
>>> other number is True. I think.
>>
>>
>> The rules are very simple. Anything that represents "something" is
>> true, and anything that represents "nothing" is false. An empty
>> string, an empty list, an empty set, and the special "None" object
>> (generally representing the absence of some other object) are all
>> false. A string with something in it (eg "Hello"), a list with
>> something in it (eg [1,2,4,8]), etc, etc, are all true.
>
>
> But even with ordinary conditionals, False is False, but [False] is True.
> And [] is False, while [[]] is True. A class instance is always True, even
> when empty. And then "False" is True as well!

[False] is a list with something in it. So is [[]]. "False" is a
string with something in it, and honestly, if you think that ought to
come out falsey, you're asking for magic. I don't know what you mean
by a "class instance", or how it would be empty, but if you're
creating a custom class and it might sometimes represent emptiness,
you need to define either __len__ or __bool__ so the interpreter can
understand what you mean by "empty".

> Maybe I was thinking of 'is' where sometimes the results are unintuitive.
>

Not at all. The 'is' operator tells you whether the left and right
operands are the same object. That's it. Maybe you have unintuitive
situations where you don't realize you have the same object (or don't
realize you have different objects), but the operator itself still has
one very simple rule to follow.

ChrisA

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


Thread

Break and Continue: While Loops Elizabeth Weiss <cake240@gmail.com> - 2016-06-22 21:17 -0700
  Re: Break and Continue: While Loops Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-06-22 21:49 -0700
    Re: Break and Continue: While Loops Elizabeth Weiss <cake240@gmail.com> - 2016-06-26 12:08 -0700
  Re: Break and Continue: While Loops Rustom Mody <rustompmody@gmail.com> - 2016-06-22 22:05 -0700
    Re: Break and Continue: While Loops Elizabeth Weiss <cake240@gmail.com> - 2016-06-26 12:09 -0700
  Re: Break and Continue: While Loops DFS <nospam@dfs.com> - 2016-06-23 01:20 -0400
    Re: Break and Continue: While Loops Elizabeth Weiss <cake240@gmail.com> - 2016-06-26 12:09 -0700
  Re: Break and Continue: While Loops Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-06-23 18:28 +1000
  Re: Break and Continue: While Loops alister <alister.ware@ntlworld.com> - 2016-06-23 09:53 +0000
  Re: Break and Continue: While Loops BartC <bc@freeuk.com> - 2016-06-23 11:15 +0100
    Re: Break and Continue: While Loops Chris Angelico <rosuav@gmail.com> - 2016-06-23 21:39 +1000
      Re: Break and Continue: While Loops Jon Ribbens <jon+usenet@unequivocal.co.uk> - 2016-06-23 11:57 +0000
        Re: Break and Continue: While Loops Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-06-26 00:32 -0700
          Re: Break and Continue: While Loops Steven D'Aprano <steve@pearwood.info> - 2016-06-26 22:18 +1000
      Re: Break and Continue: While Loops BartC <bc@freeuk.com> - 2016-06-23 16:52 +0100
        Re: Break and Continue: While Loops Chris Angelico <rosuav@gmail.com> - 2016-06-24 02:23 +1000
        Re: Break and Continue: While Loops pdorange@pas-de-pub-merci.mac.com (Pierre-Alain Dorange) - 2016-06-24 09:53 +0200
  Re: Break and Continue: While Loops John Gordon <gordon@panix.com> - 2016-06-23 17:34 +0000
  Re: Break and Continue: While Loops Elizabeth Weiss <cake240@gmail.com> - 2016-06-26 12:42 -0700
    Re: Break and Continue: While Loops Quivis <quivis@domain.invalid> - 2016-06-28 23:32 +0000

csiph-web