Python pow

The Python pow function is used to calculate the Power of the specified expression and the syntax it 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 the base value and 2 is the exponent, then the Python 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 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.

  1. Within the first three statements, We passed both the positive and negative integers as the arguments. From the above screenshot, you can observe that the Python math pow power 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 method is working correctly on them.
  3. We assigned multiple values as base arguments.
  4. Last, We tried on the String value, and it returned TypeError.
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 of Positive Number = %.2f' %math.pow(2, 3))
print('Calculating of Negative Number = %.2f' %math.pow(-2, 3))
print('Calculating of String Number = ', math.pow(2, -3))

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

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

print('Calculating of String Value = ', math.pow('2', 3))
Python POW Function