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
python_maths.htm
Advertisements
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy