2
%的文檔中,math.pow
功能操作爲:爲什麼在x ** y不?時math.pow會拋出OverflowError?
def pow(x, y):
"""
pow(x, y)
Return x**y (x to the power of y).
"""
pass
我有大量決定勾搭,但是當我運行此我收到一個錯誤:
import math
calc = math.pow(1000, 103)
print(calc)
Traceback (most recent call last):
File "test.py", line 3, in <module>
print(math.pow(1000, 103))
OverflowError: math range error
然而,後續的做沒有錯誤:
calc = 1000 ** 103
print(calc)
>> (very large number)
如果math.pow
是假設作爲x**y
,爲什麼它會拋出一個OverflowError
而明確做x**y
不?
難道是你使用的變量數量太大? – ryekayo
嘗試小整數的參數;你會看到'pow'返回一個'int',而'math.pow'返回一個'float'。這兩者並不完全相同。 – chepner