x = 1.5 * 10 ** 156
print(x * x)
print(x ** 2)
Run Code Online (Sandbox Code Playgroud)
x * x并且x ** 2在数学上是等价的。但当x较大时,前者可以返回 的结果inf,而后者会引发溢出错误。
x = 1.5 * 10 ** 156
print(x * x)
print(x ** 2)
Run Code Online (Sandbox Code Playgroud)
为什么会这样呢?