Python 溢出错误何时产生?

When is a Python Overflow Error generated?

为什么下面三行在 python3 中产生不同的输出,尽管值相等?

>>> 10 ** 500
100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

>>>1E500
inf

>>>1E250 ** 2
---------------------------------------------------------------------------
OverflowError                             Traceback (most recent call last)
<ipython-input-110-d71dbae32ab9> in <module>
----> 1 1E250**2

它们不相等。第一个是整数,Python允许整数无限大。 (好吧,实际上是无限的。)另外两个是浮点数,值超出了双精度的范围。 1E500 值是一个常量,常量溢出导致 inf pseudo-value。最后一个是算术运算,Python检测并抛出算术运算溢出