How to find exponential value in Python?


In this article, we will show you how to find the exponential value in python. Below are the various methods to accomplish this task −

  • Using exponential operator(**)

  • Using exp() function

  • Using exp() values with inbuilt numbers

  • Using pow() function

Using exponential operator(**)

The exponential operator(**) can be used to calculate the power of a number.

Since importing a module or calling a function is not necessary, this is the most convenient to use.

The exponential value of an x is xth power of e, Euler's constant which is an irrational number called Euler's number and is equal to 2.718281.

Algorithm (Steps)

Following are the Algorithm/steps to be followed to perform the desired task −

  • Use the import keyword to import the math module.

  • Get the exponential value of a number i.e, e power 2 here (where e= Euler's constant i.e 2.718281) using the exponential operator(**). We get the value of e using math.e in python.

Example

The following program returns the exponential value of a number using the exponential operator(**). −

# importing math module import math # getting the exponential value of e power 2 # (where e= Euler's constant i.e 2.718281) print("Exponential value of e power 2(e^2):", math.e**2)

Output

On executing, the above program will generate the following output −

Exponential value of e power 2(e^2): 7.3890560989306495

Using exp() function

The exp() function of the math module is used to calculate the power of e i.e. e^x or the exponential of x. The value of e is approximately around 2.71828….

Syntax

math.exp(x)

Parameters

  • x(required) − any number either positive or negative. If x has a value other than a number, it will throw an error.

Return Value  calculates e^x and returns a floating point number.

Algorithm (Steps)

Following are the Algorithm/steps to be followed to perform the desired task −

  • Import Math module

  • Use the exp() function of the math module to get the exponential value of a positive number passed as an argument to it i.e, e power 2 here (where e= Euler's constant i.e 2.718281).

  • Print the output.

Example

The following program returns the exponential value of a positive number using the exp() function −

# importing math module import math # getting the exponential value of e power 2 using the exp() function # (where e= Euler's constant i.e 2.718281) print("Exponential value of e power 2(e^2):", math.exp(2))

Output

On executing, the above program will generate the following output −

Exponential value of e power 2(e^2): 7.38905609893065

For negative numbers and floating-point numbers

Example

The following program returns the exponential value of negative and floating−point numbers using the exp() function −

# importing math module import math # getting the exponential value of a negative number using exp() print("Exponential value of e power -2(e^-2):", math.exp(-2)) # getting the exponential value of a floating-point number print("Exponential value of e power 1.5(e^1.5):", math.exp(1.5)) # getting the exponential value of 0 print("Exponential value of e power 0(e^0):", math.exp(0))

Output

On executing, the above program will generate the following output −

Exponential value of e power -2(e^-2): 0.1353352832366127
Exponential value of e power 1.5(e^1.5): 4.4816890703380645
Exponential value of e power 0(e^0): 1.0

Using exp() values with inbuilt numbers

Example

The following program returns the exponential values of inbuilt numbers like math.pi, math.e using exp() function −

# importing math module import math # getting the exponential value of inbuilt number math.pi # using exp() function print ("Exponential value of inbuilt number math.pi:", math.exp(math.pi)) # getting the exponential value of inbuilt number math.e print ("Exponential value of inbuilt number math.e:", math.exp(math.e))

Output

On executing, the above program will generate the following output −

Exponential value of inbuilt number math.pi: 23.140692632779267
Exponential value of inbuilt number math.e: 15.154262241479262

Using pow() function

In Python, the pow() function calculates the power of any positive integer. It returns the value of x to the power of y (x^y).

Syntax

pow(x,y)

Parameters

  • x − It is the numerical value (base value)

  • y − It is the power of numerical value (exponent value)

Algorithm (Steps)

Following are the Algorithm/steps to be followed to perform the desired task −

  • Create a variable to store the input base value which is e here(where e= Euler's constant i.e 2.718281). Get the value of e using math.e.

  • Create another variable to store the exponent value.

  • Use the pow() function to print the resultant power of a number i.e, base^ exponent by passing the input base, and exponent values as arguments to it and print the resultant power.

Example

The following program returns the exponential value of the input number using the pow() function −

# importing math module import math # input base value which is e (where e= Euler's constant i.e 2.718281) inputBase = math.e # input exponent value inputExponent = 3 # printing the resultant power value using the pow() function print("Value of e raised to the power 3(e^3)=", pow(inputBase, inputExponent))

Output

On executing, the above program will generate the following output −

Value of e raised to the power 3(e^3)= 20.085536923187664

Conclusion

We learned how to find the exponential number in Python using several ways in this tutorial. We also studied how the exp() function works with various types of numbers.

Updated on: 09-Nov-2022

7K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements