How to calculate the exponential value in Python?

Let’s learn how to calculate the exponential value in Python. This knowledge can be valuable in various scientific, engineering, and mathematical applications.

Python exponential calculations

Using the Exponentiation Operator

The easiest way to calculate the exponential value in Python is to use the exponentiation operator (**) double asterisk.

my_base = 5
my_exponent = 3
print ("Exponential value equals: ", my_base ** my_exponent)

my_base = 5
my_exponent = -3
print ("Exponential value equals: ", my_base ** my_exponent)

my_base = -5
my_exponent = 3
print ("Exponential value equals: ", my_base ** my_exponent)

my_base = -5
my_exponent = -3
print ("Exponential value equals: ", my_base ** my_exponent)

Python exponential calculations

Using a pow method

Alternatively, you can use the pow function from the math module.

import math

my_base = 5
my_exponent = 3
print ("Exponential value equals: ", math.pow(my_base, my_exponent))

my_base = 5
my_exponent = -3
print ("Exponential value equals: ", math.pow(my_base, my_exponent))

my_base = -5
my_exponent = 3
print ("Exponential value equals: ", math.pow(my_base, my_exponent))

my_base = -5
my_exponent = -3
print ("Exponential value equals: ", math.pow(my_base, my_exponent))

Python exponential calculations

Using an exp method

In case you would like to calculate the exponential value of Euler’s constant number you need to use exp method of math module.

import math

my_exponent = 3
print ("Exponential value equals: ", math.exp(my_exponent))

Python Euler constant exponential calculations

See also  Creating a Basic Blockchain with Python