我是Python新手。 ** => 运算符用于计算指数。
print(2 ** 3) //8
print(-2 ** 3) //-8
print(-2 ** 2) //-4
它应该只打印 4,对吗?
最佳答案
参见6.5. The power operator 。更具体地说:
Thus, in an unparenthesized sequence of power and unary operators, the operators are evaluated from right to left (this does not constrain the evaluation order for the operands): -1**2 results in -1.
关于python-3.x - Python ** 对于负数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72955383/