Find cube root of a number in Python
In this tutorial, we are going to learn how to find the cube root of a number in Python.
How to find the cube root of a number in Python
Let us understand with an example.
Suppose a number stored in a variable.
We can find the cube root of 125 using a trick :
As we know that the cube root of 125 is 5. So it will return 5.
Note:- This trick will not work in case of negative integers
If we want to find the cube root of a negative integer. Then we have to make some changes in the above trick.
Function to find cube root using Python:
We can define a function for cube root. When a user inputs a number for cube root, it will automatically return the cube root of the number.
def cube_root(x): return x**(1/3) print(cube_root(27))
As we can see, I have defined a function cube root. And I have called the same function with input 27. So it will return the cube root of 27.
You may also read: