python-3.x - Python ** 对于负数

标签 python-3.x

我是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/

相关文章:

Python3移植: TypeError: unorderable types: dict() < int()

autocomplete - 使用 Python 的 Cmd.cmd 完成选项卡

python - 如何使用 dask 读取 csv 并处理行?

python - 如何通过 selenium p 隐藏 chromedriver 登录控制台

python - 合并返回奇数长度

python - 比较两列中的两个数据帧并获取差异

Python:任何()意外的表现

python - 我可以使用 Python 的 Min 函数返回所有最小元组的列表吗?

python - 无法导入 WMI Python 模块

python - 为什么Python中进程数大于CPU线程总数时应用程序可以运行得更快?