Friday, October 3, 2025
HomeLanguagesPython math library | exp() method

Python math library | exp() method

Python has math library and has many functions regarding it. One such function is exp(). This method is used to calculate the power of e i.e. e^y or we can say exponential of y. The value of e is approximately equal to 2.71828…..

Syntax : math.exp(y) 
Parameters : y [Required] – It is any valid python number either positive or negative. Note that if y has value other than number then its return error. 
Returns: Returns floating point number by calculating e^y.

Time Complexity: O(1)
Auxiliary Space: O(1)

Code # 1: 

python3




# Python3 code to demonstrate
# the working of exp()
import math
 
# initializing the value
test_int = 4
test_neg_int = -3
test_float = 0.00
 
# checking exp() values
# with different numbers
print (math.exp(test_int))
print (math.exp(test_neg_int))
print (math.exp(test_float))


Output:

54.598150033144236
0.049787068367863944
1.0

  Code #2: 

python3




# Python3 code to demonstrate
# the working of exp()
import math
 
# checking exp() values
# with inbuilt numbers
print (math.exp(math.pi))
print (math.exp(math.e))


Output:

23.140692632779267
15.154262241479262

Code #3: TypeError 

python3




# Python3 code to demonstrate
# the working of exp()
import math
 
# checking for string
print (math.exp("25"))


Output:

Traceback (most recent call last):
  File "/home/c7ae4f1bef0ed8c7756b3f55e7d2ce81.py", line 6, in 
    print (math.exp("25"))
TypeError: a float is required
RELATED ARTICLES

Most Popular

Dominic
32331 POSTS0 COMMENTS
Milvus
85 POSTS0 COMMENTS
Nango Kala
6703 POSTS0 COMMENTS
Nicole Veronica
11867 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11929 POSTS0 COMMENTS
Shaida Kate Naidoo
6818 POSTS0 COMMENTS
Ted Musemwa
7080 POSTS0 COMMENTS
Thapelo Manthata
6775 POSTS0 COMMENTS
Umr Jansen
6776 POSTS0 COMMENTS