To get the value of Euler’s Constant e in Python, the easiest way is to use the Python math module constant e. math.e returns the value 2.718281828459045.
import math
print(math.e)
#Output:
2.718281828459045
In Python, we can easily get the value of e for use in various equations and applications with the Python math module.
To get the value of the constant e in your Python code, you just need to import the math module and call it as shown below.
import math
print(math.e)
#Output:
2.718281828459045
You can also import e from the math module and call it as shown in the following Python code.
from math import e
print(e)
#Output:
2.718281828459045
Using math.exp() to Get Euler’s Number e in Python
Another way we can get e in Python is with the math module exp() function. exp() allows us to easily exponentiate e to a given power.
If we pass ‘1’ to exp() we can get e.
Below is how to use the math exp() function get the value of e in Python.
import math
print(math.exp(1))
#Output:
2.718281828459045
Using numpy to Get Euler’s Number e in Python
Finally, we can use numpy to get Euler’s Number e for use in our Python code.
numpy also implements the exp() function and if we pass ‘1’, we can get the constant e.
Below is how to use the numpy exp() function to get the constant e.
import numpy as np
print(np.exp(1))
#Output:
2.718281828459045
Hopefully this article has been helpful for you to understand how to find the value of e from the Python math module.