A small quiz question
Steve D'Aprano
steve+python at pearwood.info
Wed Aug 16 21:03:26 EDT 2017
On Thu, 17 Aug 2017 09:12 am, Dennis Lee Bieber wrote:
> I suppose, the two in combination imply that the calls to "f()" occur
> first in left to right, but then the "**" are applied to the returned
> values right to left -- rather than having the calls performed in the
> exponentiation order.
Standard mathematical convention is for exponentiation to be performed from
right to left:
2**3**2
should be evaluated as
2**(3**2) = 512
rather than (2**3)**2 = 64. This is more obvious in the standard formatted
mathematical notation where each subsequent index is higher and smaller than
the previous, indicating that 2 is being raised to the power of 3 squared,
rather than 2 cubed being squared.
See, for example, the comment here:
http://mathworld.wolfram.com/PowerTower.html
where z^z^z is an abbreviation for z^(z^z)
(about a third of the way down the page).
So Python agrees with the usual maths convention here.
--
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.
More information about the Python-list
mailing list