math.pow(x, y) raises x to the power y, converting both arguments to float and always returning a float.
Unlike Python's built-in pow() function, math.pow() has no third modulus argument, never returns an int or complex, and raises ValueError on invalid real domains like negative bases with non-integer exponents.
math.pow() is a function in Python's standard math module: import it with import math and call math.pow(...), or import the name directly with from math import pow.
Syntax
Import math and pass base and exponent.
python
import math
result = math.pow(x, y)
Call
What it does
math.pow(2, 10)
Returns 1024.0 (float, not int).
math.pow(9, 0.5)
Returns 3.0.
math.pow(1.0, float("nan"))
Returns 1.0 (IEEE 754 special rule).
math.pow(0.0, -1)
Raises ValueError: domain error.
Use built-in pow() or ** when you need exact integer arithmetic or modular exponentiation pow(a, b, mod).
Function signatures
python
math.pow(x, y, /)
# converts x and y to float; always returns float
Parameters
Parameter
Description
x
Required positional base (int or float).
y
Required positional exponent (int or float).
Return Value
Return Value
Description
float
x raised to y. Always a float, even when both inputs are integers.
Python Examples
Example 1 — Compute Compound Interest Balances
Grow an initial deposit over multiple horizons using math.pow(1 + rate, years).
python
import math
principal = 1000.0
rate = 0.05
for years in [1, 5, 10, 20]:
balance = principal * math.pow(1.0 + rate, years)
print(f"year {years:>2}: {balance:.2f} USD")
Output
year 1: 1050.00 USD
year 5: 1276.28 USD
year 10: 1628.89 USD
year 20: 2653.30 USD
How It Works
Growth factor. Adding one to the annual rate produces the yearly multiplier 1.05.
Exponential compounding.math.pow(1.05, years) multiplies the factor across each horizon as a float.
Currency formatting. Rounding to two decimals with :.2f displays clean dollar balances.
Example 2 — Compare math.pow() With Built-in pow() and **
Contrast return types, overflow on large integers, and negative fractional exponents.
Integer range. Python integers scale effortlessly to 401 digits for 10 ** 400, while math.pow(10, 400) overflows IEEE 754 float limits.
Real domain only. Unlike (-8) ** 0.5 which produces a complex number, math.pow() rejects non-integer exponents on negative bases.
Example 3 — Inspect Special Powers of One, Zero, and Negatives
Verify how math.pow() handles zero exponents, NaN bases, and integer powers of negatives.
python
import math
print(math.pow(1.0, float("nan")))
print(math.pow(float("nan"), 0.0))
print(math.pow(0.0, 0.0))
print(math.pow(-2.0, 3))
try:
math.pow(0.0, -2)
except ValueError:
print("zero to a negative power raises ValueError")
Output
1.0
1.0
1.0
-8.0
zero to a negative power raises ValueError
How It Works
One to anything is one. Even with a NaN exponent, IEEE 754 defines math.pow(1.0, nan) as 1.0.
Anything to zero is one. Raising NaN or zero to power 0.0 returns 1.0.
Integer exponent on negative. Raising -2.0 to exact integer 3 succeeds and produces -8.0.
Zero with negative exponent.math.pow(0.0, -2) raises ValueError instead of dividing by zero.
Frequently Asked Questions
math.pow() converts arguments to float, always returns a float, and takes only two arguments. Built-in pow() keeps integers exact and accepts an optional third modulus argument.
math.pow() operates in IEEE 754 double precision, which tops out near 1.8e308, whereas ** on integers uses arbitrary-precision integers.
No. Pass three integers to the built-in pow(base, exp, mod) instead.
Python follows the IEEE 754 standard where 1**y is 1.0 for every y, including inf and nan, and x**0.0 is 1.0 for every x.
Use cmath.pow() for complex results, or math.cbrt() specifically for real cube roots in Python 3.11+.