'e' the base of natural logarithm in python

1.2k Views Asked by At

name 'e' is not defined I ma getting this error in my python code. I have already imported the math and the numpy modules. What more do I need?

2

There are 2 best solutions below

0
On BEST ANSWER

Use

import math

math.e

Similar, for example:

import math

math.pi

This way, it is clear which e (or pi) or meant, instead of a random letter e somewhere in your code.

If you are using NumPy instead, you could do as follows:

import numpy as np

np.e

(the NumPy import is generally abbreviated to np).

Both e's are the same.

2
On

try:

from math import e

You can now use 'e' in you code

or

import math
math.e

math.e will function as a float in your code