pow(-1,0) = 1, -1**0 = -1, why?

Gary Herron gherron at aw.sgi.com
Tue Dec 19 20:17:08 CET 2000


Kirby Urner wrote:
> 
>  Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32
>  Type "copyright", "credits" or "license" for more information.
>  IDLE 0.6 -- press F1 for help
> 
>  >>> -1**0
>  -1
>  >>> pow(-1,0)
>  1
>  >>> -10**0
>  -1
>  >>> pow(-10,0)
>  1
> 
You're getting confused by operator precedence here.

The expression
  -1**0 
is interpreted as
  -(1**0)
evaluates, with no surprises, to
  -1.

On the other hand,
  (-1)**0
evaluates to
  1,
as does pow(-1,0).

-- 
Dr. Gary Herron <gherron at aw.sgi.com>
206-287-5616
Alias | Wavefront
1218 3rd Ave, Suite 800, Seattle WA 98101




More information about the Python-list mailing list