Let’s learn How to calculate the exponential value in Python.
Using an asterisk
The easiest way to calculate the exponential value in Python is to use the exponentiation operator (**) double asterisk.
my_base = 5 my_exponent = 3 print ("Exponential value equals: ", my_base ** my_exponent) my_base = 5 my_exponent = -3 print ("Exponential value equals: ", my_base ** my_exponent) my_base = -5 my_exponent = 3 print ("Exponential value equals: ", my_base ** my_exponent) my_base = -5 my_exponent = -3 print ("Exponential value equals: ", my_base ** my_exponent)
Using a pow method
You can also write in the different way by using the pow function of math module.
import math my_base = 5 my_exponent = 3 print ("Exponential value equals: ", math.pow(my_base, my_exponent)) my_base = 5 my_exponent = -3 print ("Exponential value equals: ", math.pow(my_base, my_exponent)) my_base = -5 my_exponent = 3 print ("Exponential value equals: ", math.pow(my_base, my_exponent)) my_base = -5 my_exponent = -3 print ("Exponential value equals: ", math.pow(my_base, my_exponent))
Using an exp method
In case you would like to calculate the exponential value of Euler’s constant number you need to use exp method of math module.
import math my_exponent = 3 print ("Exponential value equals: ", math.exp(my_exponent))