math.pow

Full name
math.pow
Library
math
Syntax

math.pow(x, y)

Description

The math.pow function returns the result of raising x to y. Unlike the built-in function pow or the ** operator, math.pow always returns a real number, even if x and y are integers.

math.pow(1.0, x) and math.pow(x, 0.0) always return 1.0, regardless of the value of x. If x is a negative number and y is not an integer, math.pow(x, y) generates an error of type ValueError.

Parameters
  • x: Power base.
  • y: Exponent of the power.
Result

The math.pow function returns a real number.

Examples

We can obtain the result of raising the number 2.5 to 3.6 with the following code:

math.pow(2.5, 3.6)
27.07597043574791

The result returned by the function is a real number even though the base and the exponent are integers:

math.pow(2, 3)
8.0
Submitted by admin on Mon, 02/01/2021 - 08:16