Python pow

The Python pow function is used to calculate the Power of the specified expression. The syntax of the math pow Function is

math.pow(base, Exponent);
  • Base: Please specify the base value here.
  • Exponent: Please specify the Exponent value or power here.

For example, if x is base value and 2 is exponent, then the Math.pow(x, 2) = x²

NOTE: If the Base value or Exponent value argument is not a number, the pow function returns TypeError.

Python pow Function Example

The Python pow function returns the Power of the given number. In this example, we are going to find the power of different data types and display the output

import math

Tup = (10.98, 20.26, 12.05, -40.95 , 50.45) # Tuple Declaration
Lis = [-10.98, 32.65, -39.59, -42.15 , 15.97] # List Declaration

print('Calculating Power of Positive Number = %.2f' %math.pow(2, 3))
print('Calculating Power of Negative Number = %.2f' %math.pow(-2, 3))
print('Calculating Power of String Number = ', math.pow(2, -3))

print('Calculating Power of of Tuple Item = %.2f' %math.pow(Tup[2], 2))
print('Calculating Power of List Item = %.2f' %math.pow(Lis[4], 4))

print('Calculating Power of Multiple Number = %.2f' %math.pow(1 + 2 - 12.65, 2))

print('Calculating Power of String Value = ', math.pow('2', 3))
Python POW Function
  1. Within the first three statements, We passed both the Positive integer and negative integer as the math pow Function arguments. From the above screenshot, you can observe that the Python math pow power function Function is returning output.
  2. Next, We used the Tuple and List items as base arguments and integer value as an exponent. If you see the above Python image, the Math function is working correctly on them.
  3. We assigned multiple values as base arguments.
  4. Last, We tried on the String value, and it returns TypeError.