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: 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 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Sun, Aug 12, 2012 at 8:30 AM, John Ladasky wrote: > In [7]: 1 + not(len(L) % 2) > ------------------------------------------------------------ > File "", 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