Related Tags

Calculating the exponential value in Python


In Mathematics, the exponential value of a number is equivalent to the number being multiplied by itself a particular set of times.

The number to be multiplied by itself is called the base and the number of times it is to be multiplied is the exponent.

How to calculate the exponential value of a number

Python allows users to calculate the exponential value of a number in multiple ways. Let’s look at each of them in detail!

1. ** operator

The double asterisk, ** operator is a shortcut to calculate the exponential value. Let’s take a look at how this can be used in the following code:

base = 3
exponent = 4
print "Exponential Value is: ", base ** exponent

2. pow( )

In addition to the ** operator, Python has included a built-in pow() function which allows users to calculate the exponential value.

The function takes as input the base and exponent and returns the corresponding value. The general syntax of the function is:

pow(base, exponent)

Look at the coding example to see how it works:

base = 3
exponent = 4
print "Exponential Value is: ", pow(base, exponent)

3. exp( )

The exp() function in Python allows users to calculate the exponential value with the base set to e.

Note:

  1. e is a Mathematical constant, with a value approximately equal to 2.71828.
  2. The math library must be imported for this function to be executed.

The function takes as input the exponent value. The general syntax of the function is:

math.exp(exponent)

Execute the following piece of code to see the result!

import math

exponent = 4
print "Exponential Value is: ", math.exp(exponent)
RELATED COURSES
View all Courses