Python math.pow() - Power of a Number
Python math.pow()
math.pow(x, y) function returns the value of x raised to the power y.
Syntax
The syntax to call pow() function is
math.pow(x, y)
where
Parameter | Required | Description |
---|---|---|
x | Yes | A numeric value. |
y | Yes | A numeric value. |
If x and y are finite, x < 0, and y is not integer, then pow() raises ValueError.
Examples
In the following program, we find the 4 raised to the power of 3.
Python Program
import math
x = 4
y = 3
result = math.pow(x, y)
print('pow(x, y) :', result)
Output
pow(x, y) : 64.0
x and y are finite, x < 0, and y is not an integer.
Python Program
import math
x = -1
y = 3.235
result = math.pow(x, y)
print('pow(x, y) :', result)
Output
ValueError: math domain error
Infinity raised to the power of y.
Python Program
import math
x = math.inf
y = 3
result = math.pow(x, y)
print('pow(x, y) :', result)
Output
pow(x, y) : inf
x raised to the power of infinity.
Python Program
import math
x = 3
y = math.inf
result = math.pow(x, y)
print('pow(x, y) :', result)
Output
pow(x, y) : inf
x raised to the power of 0.
Python Program
import math
x = 3
y = 0
result = math.pow(x, y)
print('pow(x, y) :', result)
Output
pow(x, y) : 1.0
Summary
In this Python Examples tutorial, we learned the syntax of, and examples for math.pow() function.