Arithmetic operations in Python are right-to-left, not left-to-right?

A simple example in Python caused me confusion:

d = 15.961599999999999
d ** 1.5
>>>63.76973829534582
d ** 0.5 ** 3
>>>1.4137888521577402
0.5 ** 3
>>>0.125
d ** 0.125
>>>1.4137888521577402

Question: why does Python first perform the construction of 0.5 ** 3, and only then d ** (0.5 ** 3). Shouldn't arithmetic operations be performed from left to right? (d ** 0.5) ** 3

Author: Chudvan, 2019-09-04

2 answers

From the documentation (Python: table of operator precedence):

Operators in the same box group left to right (except for exponentiation, which groups from right to left).

 9
Author: MaxU, 2019-09-04 06:06:35

Python counts correctly, first the degree to the degree is raised, and then the base to the degree. It is for this reason that d ** 0.125, so that it is as you want, put the brackets.

 0
Author: Leon, 2019-09-04 03:56:58