Python expm1

The Python expm1 math function is to calculate the power of E (Where E is Euler’s number approximately equal to 2.71828) and subtracts One from it. In this section, we discuss how to use expm1 function in Python with example.

The syntax of the expm1 Function in Python Programming Language is


Or we can simply say math.exp(number) – 1. Please refer Python exp function for further reference.

Number: It can be a number or a valid numerical expression.

  • If the number argument is a positive or negative number, the expm1 function returns the output.
  • If the number argument is not a number, expm1 function return TypeError.

Python expm1 Function Example

The Python expm1 Function calculates the power of Euler’s number E and subtracts One from it. In this example, we use expm1 to find the power of e of different data types.

# Python expm1 Function

import math

Tup = (1.98, 20.26, 13.05, -40.95 , 0.45) # Tuple Declaration
Lis = [-10.98, 3.65, -9.59, -4.15 , 5.97] # List Declaration

print('EXPM1() Function on Positive Number = %.2f' %math.expm1(1))
print('EXPM1() Function on Negative Number = %.2f' %math.expm1(-1))

print('EXPM1() Function on Tuple Item = %.2f' %math.expm1(Tup[2]))
print('EXPM1() Function on List Item = %.4f' %math.expm1(Lis[2]))

print('EXPM1() Function on Multiple Number = %.4f' %math.expm1(10 + 20 - 15.65))

print('EXPM1() Function on String Value = ', math.expm1('3'))

Python EXPM1 Function

  1. First, We declared Python List and Python Tuple with some random values.
  2. Within the first two statements, We used the expm1 Function with both the Positive integer and negative integer values as arguments.
  3. Next two statements, We used the expm1 Function on Python Tuple and List items. If you observe the above screenshot, the expm1 function is working perfectly on them.
  4. Next, we tried the expm1 Math function directly on multiple values.
  5. In the Last statement, We used the expm1 Function on the String value. As we said before, it returns TypeError as output.