In Python, the easiest way we can find the cube root of a number is to use the pow() function from the Python math module.
import math
cube_root_of_10 = math.pow(10,1/3)
You can also use the built in ** operator to find the cube root of a number.
cube_root_of_10 = 10**(1/3)
The Python math module has many powerful functions which make performing certain calculations in Python very easy.
One such calculation which is very easy to perform in Python is finding the cube root of a number.
The pow() function from the Python math module also lets us compute cube roots.
The pow() function takes two numbers as input, the first number is the base and the second number is the exponent. The first number must be positive, but the second number can be negative.
For a cube root, we pass “1/3” to the second parameter in the pow() function.
Below are some examples of how to use the pow() function to find cube roots.
import math
print(math.pow(4, 1/3))
print(math.pow(9, 1/3))
print(math.pow(13, 1/3))
print(math.pow(90, 1/3))
print(math.pow(2182, 1/3))
#Output:
1.5874010519681994
2.080083823051904
2.3513346877207573
4.481404746557164
12.970346612351785
The Python pow() function can also be useful if you want to find the square root of a number or the nth root of a number in Python.
Finding the Cube Root of a Number with the ** Operator in Python
We can also use the built in ** to perform exponentiation in Python. To find a cube root with the ** operator, we just put “(1/3)” after **.
Unlike the pow() function, we can find the cube root of negative numbers with the ** operator.
Below are some examples of how to use the Python built in ** operator to find cube roots.
import math
print(4**(1/3))
print(9**(1/3))
print(-13**(1/3))
print(90**(1/3))
print(-2182**(1/3))
#Output:
1.5874010519681994
2.080083823051904
-2.3513346877207573
4.481404746557164
-12.970346612351785
Hopefully this article has been beneficial for you to learn how to find the cube root of a number in Python.