What is math.pow() in Python?

Share

The pow() function calculates the value of the numberbase raised to the power of another numberexponent.

Figure 1 shows the mathematical representation of the pow() function.

Figure 1: Mathematical representation of pow() function

The math module is required for this function.

Syntax

pow(baseNumber, exponent)

Parameters

The pow() function requires two parameters:

  • A base number.
  • An exponent number.

Return value

pow() returns the value of the base number raised to the exponent number.

Example

import math
#positive: baseNumber positive: exponent
print "The value of pow(2,3) : ", math.pow(2,3)
#positive: baseNumber negative: exponent
print "The value of pow(0.25,-2) : ", math.pow(0.25,-2)
#negative: baseNumber positive: exponent
print "The value of pow(-10,2) : ", math.pow(-10,2)
#negative: baseNumber negative: exponent
print "The value of pow(-0.5,-1) : ", math.pow(-0.5,-1)