Python math.exp() function


The math.exp() function in Python is used to calculate the exponential of a given number. Specifically, it computes exe^x, where ee is Euler's number (approximately 2.71828), and xx is the input value.

Syntax

import math result = math.exp(x)
  • x: A numeric expression (integer or float) for which you want to calculate the exponential.

Return Value

  • Returns the value of exe^x as a float.

Examples

  1. Calculating the exponential of a positive number:

    import math result = math.exp(1) # e^1 print(result) # Output: 2.718281828459045 (approximately)
  2. Calculating the exponential of zero: The exponential of zero is always 1.

    result = math.exp(0) print(result) # Output: 1.0
  3. Calculating the exponential of a negative number:

    result = math.exp(-1) # e^-1 print(result) # Output: 0.36787944117144233 (approximately)
  4. Calculating the exponential of a large number:

    result = math.exp(10) print(result) # Output: 22026.465794806718 (approximately)
  5. Using math.exp() in mathematical expressions: You can use math.exp() in combination with other mathematical functions:

    value = 2 result = math.exp(value) + 5 print(result) # Output: 7.718281828459045 (approximately)

Summary

  • The math.exp() function computes the exponential of a number, returning exe^x.
  • The result is always a float.
  • This function is widely used in various scientific and engineering applications, including calculus, compound interest calculations, and growth models in population dynamics and finance.