-2

What is the easiest/most optimal way of finding the exponential of a number, say x, in Python? i.e. how can I implement e^x?

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Marioanzas
  • 1,663
  • 2
  • 10
  • 33

2 Answers2

1

The easiest and most optimal way to do e^x in Python is:

from math import exp

print(exp(4))

Output

>>> 54.598150033144236
Khaled DELLAL
  • 871
  • 4
  • 16
0

You can use the math.exp() function from the math module (read the docs).

>>> import math
>>> x = 4
>>> print(math.exp(x))
54.598150033144236
Marioanzas
  • 1,663
  • 2
  • 10
  • 33