[Tutor] a puzzle about -3**2 vs (-3)**2

Jose Amoreira ljmamoreira at gmail.com
Fri Jul 31 11:55:19 CEST 2015


Hello!
On 07/31/2015 01:58 AM, D Wyatt wrote:
> I just read in a book a little while ago that ** trumps a negative
> sign?  I am struggling with the audacity of that as -1 is negative 1,
> NOT minus 1.

I'm not sure about what you mean by "trumps", but the square of negative 
one is positive one (negative times negative gives positive).

> How can an arithmetic operation trump an attribute of a
> negative integer?  It truly makes no sense to me.  Thank you for any
> enlightenment you can provide.
>
> Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (In
> tel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
>>>> 3**2
> 9
>>>> (-3)**2
> 9
>>>> -3**2
> -9
>>>>
>

Given the precedence rules already mentioned by Alan and Todd, the 
results of the operations you showed us are exactly as expected. You'll 
get the same results if you try with a pocket calculator or using any 
other programming language or scientific package. Or MS-excel.

HTH,
Ze


More information about the Tutor mailing list