The Python POW function is one of the Python Math function which is used to calculate the Power of the specified expression. In this article we will show you, How to use POW() function in Python Programming language with example.
Syntax of a Python POW Function
The basic syntax of the POW Function in Python Programming Language is as shown below:
- 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, Math.pow(x, 2) = x²
NOTE: If the Base value or Exponent value argument is not a number, POW() function will return TypeError.
Python POW Function Example
The Python POW function is used to return the Power of the given number. In this example, We are going to find the power of different data types and display the output
# Python POW Function
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))
print('Calculating Power of List Item = %.2f' %math.pow(Lis, 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))
- At the beginning, We declared Python List and Tuple with some random values.
- Within the first three statements, We passed both the Positive integer and negative integer as the POW() Function arguments. From the above screenshot you can observe that, POW() Function is returning output.
- Next two statements, We used the Python Tuple and List items as base arguments and integer value as exponent for POW() Function. If you observe the above screenshot, POW() function is working perfectly on them.
- Next statement, We assigned multiple values as base arguments for POW() Function.
- Last, We tried POW() Function on String value. As we said before, this will return TypeError as output
Thank You for Visiting Our Blog