What is the associativity of Python's ** operator?

前端 未结 4 1348
自闭症患者
自闭症患者 2020-12-11 04:21

I was just playing around with the python command line and the ** operator, which as far as I know performs a power function. So 2 ** 3 should be (and is) 8 because 2 * 2 *

4条回答
  •  自闭症患者
    2020-12-11 05:07

    2** (2**(2**2))
    

    from http://docs.python.org/reference/expressions.html

    Operators in the same box group left to right (except for comparisons, including tests, which all have the same precedence and chain from left to right — see section Comparisons — and exponentiation, which groups from right to left).

提交回复
热议问题