Python math.exp() | Exponential Function

Python supports an inbuilt “math” module that provides various kinds of functions to perform simple to intermediate tasks. Some popular math module functions are “math.cos()”, “math.floor()”, “math.atan()”, etc. Apart from these, there is another function named “math.exp()” that retrieves “e” raised to the power of “ x”.

This Python tutorial will provide a complete overview of Python math.exp() function with numerous examples. The scope of this article is described below:

Let’s begin our guide!

What is Python math.exp() Exponential Function?

The Python “math.exp()” function returns the “e” value raised to the power of “x” such as (). The “e” here represents the natural base of logarithms, and its value equals “2.718282”. The syntax of the “math.exp()” function is below:

math.exp(x)

In the above syntax, the parameter “x” is necessary to define inside the parentheses. The function “math.exp()” returns the exponent value of that number which is raised to the power x.

Let’s begin with our first example of Python math.exp() function:

Example 1: Exponent Power of Positive Number

In the following example, the “math.exp()” function takes the integer value inside the parentheses and returns the exponent value.

Code:

import math

Number = 90
output = math.exp(Number)
print('Exponent value:', output)

In the following code, the “math.exp()” function of the math module takes the integer value, i.e., 90, as an argument and returns the exponent value.

Output:

The above output shows the exponent power of the integer number “90”.

Example 2: Exponent Power of Negative Number

In the example below, the “math.exp()” finds the exponent value of a negative integer number.

Code:

import math

Number = -45
output = math.exp(Number)
print('Exponent value:', output)

In the above code, the “math.exp()” function of the math module takes the negative integer value as an argument and returns the exponent power value.

Output:

The above output shows the exponent power of the negative integer “90”.

Example 3: Exponent Power of Float Number

In the sample code shown below, the “math.exp()” finds the exponent value of a positive and negative float number.

Code:

import math

Number = 4.45
Number_1 = -3.23
output = math.exp(Number)
output_1 = math.exp(Number_1)

print('Exponent value:', output)
print('Exponent value:', output_1)

In the above code, the positive and negative float numbers are initialized. The “math.exp()” functions return the exponent value of a given number.

Output:

The above output shows the exponent power of the positive and negative integer numbers.

Bonus Tip: How Does math.exp() Work With Non-Numeric Values?

In the example below, the non-numeric value is passed inside the “math.exp()” function.

code:

import math

Number_1 = 'Lily'
output_1 = math.exp(Number_1)
print('Exponent value:', output_1)

In the above code, math.exp() function takes the non-numeric value as an argument and returns Type-error.

Note: if the numeric value is passed inside the string, the error will also appear in the output. So make sure to use an integer or float value while initializing.

Output:

The above code shows the “TypeError” when a non-numeric value is passed inside the “math.exp()” function.

That’s all from this math.exp() guide!

Conclusion

To calculate the exponent power of numeric value, the “math.exp()” function of the “math” module is utilized in Python. The “math.exp()” function retrieves the “e” value raised to the power of “x”. The “math.exp()” takes the value of the integer or the float number and returns the exponent power. The “math.exp()” gives a type error when other than numeric values are used, like string, list, etc. This Python blog post presented a detailed overview of the “math.exp()” function with multiple examples.