Power operator, why does -2**3 throws?

Claude Pache claude.pache at gmail.com
Fri Oct 14 15:09:04 UTC 2016


> Le 14 oct. 2016 à 16:52, Rick Waldron <waldron.rick at gmail.com> a écrit :
> 
> Python is also inconsistent: 
> 
> >>> pow(-2, 2)
> 4
> >>> -2 ** 2
> -4
> >>>

This is not inconsistency, but that follows from operator precedence rules (those used in mathematics, not in C).

In the same vein, you have `pow(1+1, 2) == 4` but `1+1 ** 2 == 2`, because the latter is interpreted as `1+(1 ** 2)`.

—Claude



More information about the es-discuss mailing list