all Python 3mathterm
math.pow
power/root
Raises x to the power of y and always returns a float. The difference from **: math.pow(-1, 0.5) raises ValueError, while ** gives a complex number.
Syntax
math.pow(x, y)
Both arguments are converted to float first, so large integers lose precision and math.pow(2, 10000) raises OverflowError, while 2 ** 10000 is computed exactly. Keep math.pow for real-valued math and use ** or the built-in pow() for integers — only the built-in accepts a third argument, the modulus, which is what modular exponentiation problems need.
Examples
import math
print(math.pow(2, 10)) # → 1024.0
print(math.pow(4, 0.5)) # → 2.0 (квадратный корень)
print(math.pow(3, 3)) # → 27.0
print(math.pow(2, -1)) # → 0.5
print(math.pow(0, 0)) # → 1.0
print(math.pow(10, 3)) # → 1000.0
See also
Open in the full glossarydocs.python.orgReport an inaccuracy