[Tutor] Re: precedence bug?

Christopher Smith csmith@blakeschool.org
Fri, 08 Feb 2002 21:56:06 -0600

mday@mac.com writes:
>On Friday, February 8, 2002, at 03:36  PM, Christopher Smith wrote:
>> The python reference (ref/summary.html) it says that 'negation' and
>> 'bitwise not' have higher precedence than exponentiation but this is n=
>> born out by the interpreter (MacPython 2.2):
>I think you're reading the table wrong.  To quote that page:
>> The following table summarizes the operator precedences=A0in Python, f=
>> lowest precedence (least binding) to highest precedence (most binding).
>And note that exponentiation is listed *after* bitwise not and=20
>negative.  That means that exponentiation has higher precedence (since=20
>it comes later in the table).

Hmmm...here it is (the reference section 5.12) in the 2.1 documents:

**		Exponentiation
+x, -x	Positive, negative
~x		Bitwise not

and here it is in the 2.2 docs:

+x, -x	Positive, negative
~x		Bitwise not
**		Exponentiation

I thought I actually had checked that it was the same in the 2.2 docs but
I see that I must have looked a the same set of docs (the 2.1 version)
twice.  Can anyone confirm that the behavior didn't change between
versions and that the documentation was just changed to reflect the actua=

I guess I would still favor not relying on the precedence rules here and
go for ease of reading and say it explicitly: -(a**2) or (-a)**2.