Python 3.11+Numbers & mathfunction
math.cbrt
roots/powers
The cube root of a number (3.11+).
Syntax
math.cbrt(...)
The reason to prefer it over exponentiation: cbrt takes the root of negative numbers directly, while (-8) ** (1/3) yields a complex number in Python 3 and math.pow(-8, 1/3) raises ValueError outright. The result is always a float and may miss an exact integer by a last-digit rounding step, so compare with math.isclose() rather than ==.
Examples
import math
print(round(math.cbrt(27), 4)) # → 3.0
print(round(math.cbrt(-8), 4)) # → -2.0
print(round(math.cbrt(0.001), 4)) # → 0.1
print(math.cbrt(0)) # → 0.0
print(math.pow(-8, 1 / 3)) # → ValueError
See also
Open in the full glossarydocs.python.orgReport an inaccuracy