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


Groups > comp.lang.python > #26926

Re: Arithmetic with Boolean values

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!feeder2.ecngs.de!ecngs!feeder.ecngs.de!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
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; 'syntax': 0.03; '(except': 0.05; 'binary': 0.05; 'python': 0.09; 'list).': 0.09; 'aug': 0.13; '"not"': 0.16; '2))': 0.16; '3.2,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'fwiw': 0.16; 'operator.': 0.16; 'parentheses': 0.16; 'subject:values': 0.16; 'syntaxerror:': 0.16; 'wrote:': 0.17; 'appears': 0.18; 'trying': 0.21; 'received:209.85.214.174': 0.21; '"",': 0.22; 'interpret': 0.22; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'message- id:@mail.gmail.com': 0.27; 'correct': 0.28; 'fine': 0.28; 'enforce': 0.29; 'file': 0.32; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'received:209.85': 0.35; '12,': 0.36; 'limitation': 0.36; 'subject:with': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'received:209.85.214': 0.39; 'header:Received:5': 0.40; 'john': 0.60
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:to :content-type; bh=1/ITZwRxvJ48B034PYYADm8cjGlMppsJKMGvI0doMFM=; b=zkF2SBFTxiEgo9RHDWJUVq+eqwAz6hn77fMJYwsmAAsje2jVDMFuj+HLZDbrKsREsj o1p2eBd2hxJK3Q0IP7XAmt7HK5MYEGfK9mCVt4aSjS7HWVUhhJPLPvwkk3ZtGMPgiPx9 XP/5VZpMVSB3l5rmXhXmEtYA2Ioz5NiRx5gtIoZpgBkSZDV72658Wtrtp/8c+X5RlNT8 q39wONAPPL68htXTEqW1ZpcXGkclkaS0sd26HZM1Y5XsDTC5GeyXCGBU09UMXH1qLi5F U6qwipm4PNGl19WjrHvx+Sbs6n5pKZmz1bA/+IPU7wrVYfr/O8EvvT50eJfU6BNopS7F hqVg==
MIME-Version 1.0
In-Reply-To <58f60e60-1dc1-4265-a601-693d11b4bcec@googlegroups.com>
References <58f60e60-1dc1-4265-a601-693d11b4bcec@googlegroups.com>
Date Sun, 12 Aug 2012 09:13:15 +1000
Subject Re: Arithmetic with Boolean values
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://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 <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3198.1344726798.4697.python-list@python.org> (permalink)
Lines 20
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1344726798 news.xs4all.nl 6901 [2001:888:2000:d::a6]:35842
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:26926

Show key headers only | View raw


On Sun, Aug 12, 2012 at 8:30 AM, John Ladasky
<john_ladasky@sbcglobal.net> wrote:
> In [7]: 1 + not(len(L) % 2)
> ------------------------------------------------------------
>    File "<ipython console>", line 1
>      1 + not(len(L) % 2)
>            ^
> SyntaxError: invalid syntax

This appears to be a limitation of the parser; it's trying to
interpret "not" as a binary operator.

1 + (not(len(L) % 2))

Works just fine with parentheses to enforce the correct interpretation.

This also works in Python 3.2, fwiw (except that you need
list(range(5)) to create the sample list).

ChrisA

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


Thread

Arithmetic with Boolean values John Ladasky <john_ladasky@sbcglobal.net> - 2012-08-11 15:30 -0700
  Re: Arithmetic with Boolean values Chris Angelico <rosuav@gmail.com> - 2012-08-12 09:13 +1000
  Re: Arithmetic with Boolean values Chris Rebert <clp2@rebertia.com> - 2012-08-11 16:53 -0700
  Re: Arithmetic with Boolean values Terry Reedy <tjreedy@udel.edu> - 2012-08-11 20:25 -0400
  Re: Arithmetic with Boolean values Chris Angelico <rosuav@gmail.com> - 2012-08-12 10:31 +1000
  Re: Arithmetic with Boolean values MRAB <python@mrabarnett.plus.com> - 2012-08-12 01:36 +0100
  Re: Arithmetic with Boolean values Paul Rubin <no.email@nospam.invalid> - 2012-08-11 17:54 -0700
    Re: Arithmetic with Boolean values Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-08-12 11:22 +0000
      Re: Arithmetic with Boolean values Roy Smith <roy@panix.com> - 2012-08-12 07:40 -0400
        Re: Arithmetic with Boolean values Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-08-12 14:06 +0000
          Re: Arithmetic with Boolean values Paul Rubin <no.email@nospam.invalid> - 2012-08-12 09:59 -0700
            Re: Arithmetic with Boolean values Bernd Nawothnig <Bernd.Nawothnig@t-online.de> - 2012-08-12 19:21 +0200
            Re: Arithmetic with Boolean values Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-08-12 19:20 +0100
              Re: Arithmetic with Boolean values Roy Smith <roy@panix.com> - 2012-08-12 14:45 -0400
              Re: Arithmetic with Boolean values Alister <alister.ware@ntlworld.com> - 2012-08-12 20:13 +0000
                Re: Arithmetic with Boolean values Gene Heskett <gheskett@wdtv.com> - 2012-08-12 20:29 -0400
                Re: Arithmetic with Boolean values Hans Mulder <hansmu@xs4all.nl> - 2012-08-14 18:32 +0200

csiph-web