Python math.cbrt() Method
The Python math.cbrt() method is used to calculate the cube root of a given number.
Mathematically, the cube root method, denoted as βx, is a mathematical operation that finds a number which, when multiplied by itself twice, gives the original number x. Mathematically, this is expressed as β
βx = y such that y3 = x
For example, if x = 8, then the cube root of 8(β8) is 2 because 23 = 8. Similarly, if x = -27, then the cube root of -27(β-27) is -3 because (-3)3 = -27.
Syntax
Following is the basic syntax of the Python math.cbrt() method β
math.cbrt(x)
Parameters
This method accepts an integer or a floating-point number as a parameter for which you want to calculate cube root.
Return Value
The method returns the cube root of the given value. The return value is also a floating-point number.
Example 1
In the following example, we are calculating the cube root of a positive integer using the math.cbrt() method β
import math
result = math.cbrt(27)
print("Cube root of 27:", result)
Output
The output obtained is as follows β
Cube root of 27: 3.0
Example 2
In here, we are calculating the cube root of a negative integer using the math.cbrt() method β
import math
result = math.cbrt(-64)
print("Cube root of -64:", result)
Output
Following is the output of the above code β
Cube root of -64: -4.0
Example 3
In this example, we are evaluating the sum of the cube root for x=3 and x + 1 using the math.cbrt() method β
import math
x = 81
result = math.cbrt(x) + math.cbrt(x+1)
print("cube root obtained is:", result)
Output
We get the output as shown below β
cube root obtained is: 8.671230196690837
Example 4
Now, we use the math.cbrt() method to calculate the cube root of a negative floating-point number β
import math
result = math.cbrt(-125.0)
print("Cube root of -125.0:", result)
Output
The result produced is as shown below β
Cube root of -125.0: -5.0