Python math.pow() Function

Beginner
5 min read
Updated: Nov 2026
3 examples
math module

Definition

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)
CallWhat 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

ParameterDescription
xRequired positional base (int or float).
yRequired positional exponent (int or float).

Return Value

Return ValueDescription
floatx 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")

How It Works

  1. Growth factor. Adding one to the annual rate produces the yearly multiplier 1.05.
  2. Exponential compounding. math.pow(1.05, years) multiplies the factor across each horizon as a float.
  3. 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.

python
import math

print(math.pow(2, 10), type(math.pow(2, 10)).__name__)
print(pow(2, 10), type(pow(2, 10)).__name__)
print(len(str(10 ** 400)))

try:
    math.pow(10, 400)
except OverflowError:
    print("math.pow overflows past float limit")

try:
    math.pow(-8, 0.5)
except ValueError:
    print("negative fractional power raises ValueError")

How It Works

  1. Type contrast. math.pow(2, 10) returns float 1024.0, whereas built-in pow(2, 10) keeps integer 1024.
  2. Integer range. Python integers scale effortlessly to 401 digits for 10 ** 400, while math.pow(10, 400) overflows IEEE 754 float limits.
  3. 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")

How It Works

  1. One to anything is one. Even with a NaN exponent, IEEE 754 defines math.pow(1.0, nan) as 1.0.
  2. Anything to zero is one. Raising NaN or zero to power 0.0 returns 1.0.
  3. Integer exponent on negative. Raising -2.0 to exact integer 3 succeeds and produces -8.0.
  4. 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+.

Next: math.prod()

Multiply all numeric elements in an iterable starting from start=1.

prod() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful