Python How To Calculate Exponents
In Python it is easy to calculate exponents, which it should be. We’re going to show you a few ways that you can do this.
To calculate an exponent in Python just use the following:
x = 3**5
There are other ways to calculate exponents but I would just stick with the syntax above as it is easier and doesn’t require the overhead of function calls.
You can use the pow function to calculate an exponent like this:
x = pow(4, 5)
There is also another version of the pow function in the math module. You can just import math and call the function.
import math
x = math.pow(3, 5)
You can also do this with numpy. This might make sense if you are already working with numpy but I would just stick with the first method we looked at above.
import numpy
x = numpy.power(5, 8)