You could use x ** (1. / 3) to compute the (floating-point) cube root of x.

The slight subtlety here is that this works differently for negative numbers in Python 2 and 3. The following code, however, handles that:

def is_perfect_cube(x):
    x = abs(x)
    return int(round(x ** (1. / 3))) ** 3 == x

print(is_perfect_cube(63))
print(is_perfect_cube(64))
print(is_perfect_cube(65))
print(is_perfect_cube(-63))
print(is_perfect_cube(-64))
print(is_perfect_cube(-65))
print(is_perfect_cube(2146689000)) # no other currently posted solution
                                   # handles this correctly

This takes the cube root of x, rounds it to the nearest integer, raises to the third power, and finally checks whether the result equals x.

The reason to take the absolute value is to make the code work correctly for negative numbers across Python versions (Python 2 and 3 treat raising negative numbers to fractional powers differently).

Answer from NPE on Stack Overflow
🌐
Delft Stack
delftstack.com › "delft stack" › "howto" › "python how-to's" › "how to calculate cube root in python"
How to Calculate Cube Root in Python | Delft Stack
February 2, 2024 - One straightforward approach to calculate the cube root of an integer or a float variable in Python is by using the exponent symbol **.
Discussions

Is there a cube root method in Python, like there is sqrt()?
def root(number, Nth_root) : return number ** (1/Nth _root) More on reddit.com
🌐 r/learnpython
5
3
April 10, 2020
How to find the cube root in Python? - Stack Overflow
I've tried to find the cube root in Python but I have no idea how to find it. There was 1 line of code that worked but he wouldn't give me the full number. Example: math.pow(64, 1/3) This doesn't ... More on stackoverflow.com
🌐 stackoverflow.com
How to get a cube root in Python - Stack Overflow
I saw this post recently, about getting square roots in python: How to calc square root in python? I have used the sqrt(x) command, but I don't know how to make it work for cube roots and anything More on stackoverflow.com
🌐 stackoverflow.com
math - Cube roots of a complex number in python - Stack Overflow
How do I calculate the cube roots of a complex number in python? Currently, the only way I've found to do it is according to this answer, but I'm trying to remove any and all import statements from... More on stackoverflow.com
🌐 stackoverflow.com
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-program-for-find-cubic-root-of-a-number
Python Program for Find cubic root of a number - GeeksforGeeks
July 23, 2025 - Initialize x to n. Compute y as (2x + n/x^2) / 3. While the absolute difference between x and y is greater than or equal to 0.000001, set x to y and compute a new value of y using the same formula as step 2. Return the final value of y. ... ...
🌐
Tutorialspoint
tutorialspoint.com › python › python_math_cbrt_method.htm
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
Find elsewhere
🌐
CodeRivers
coderivers.org › blog › how-to-take-the-cube-root-in-python
Calculating Cube Roots in Python: A Comprehensive Guide - CodeRivers
February 22, 2026 - This code will raise a ValueError because the math module is designed mainly for real-valued functions, and taking the cube root of a negative number using the standard exponentiation in the math module is not straightforward. Python allows us to use the ** operator for exponentiation.
🌐
AlphaCodingSkills
alphacodingskills.com › python › pages › python-program-cube-root-of-a-number.php
Python Program Cube Root of a Number - AlphaCodingSkills
import math x = 64 y = 125 x1 = math.pow(x, 1/3) y1 = math.pow(y, 1/3) print("Cube root of", x, "is",x1) print("Cube root of", y, "is",y1) ... AlphaCodingSkills is a online learning portal that provides tutorials on Python, Java, C++, C, C#, PHP, R, Ruby, Rust, Scala, Swift, Perl, SQL, Data Structures and Algorithms.
🌐
CodeSpeedy
codespeedy.com › home › find cube root of a number in python
Find cube root of a number in Python - CodeSpeedy
February 11, 2024 - Cube Root number = float(input( “Enter a number please? “) cube_root = number**(1/3) print(cube_root) ... This function has now been removed from Python Math library.
🌐
Finxter
blog.finxter.com › home › learn python blog › 5 best ways to calculate the cube root of a given number in python
5 Best Ways to Calculate the Cube Root of a Given Number in Python - Be on the Right Side of Change
February 27, 2024 - The pow function is a built-in Python method that can compute powers and roots. Similar to the ** operator, pow accepts two arguments, where the second argument for cube roots is 1/3.
🌐
Python-bloggers
python-bloggers.com › 2022 › 12 › python-square-roots-5-ways-to-take-square-roots-in-python
Python Square Roots: 5 Ways to Take Square Roots in Python | Python-bloggers
December 1, 2022 - Numpy provides an easier way to take cube roots in Python. It has a cbrt() function built in, which stands for cube root.
🌐
LabEx
labex.io › tutorials › python-square-root-and-cube-root-302766
Square Root and Cube Root Calculation | LabEx
If the input number is odd, calculate its square root and return the result rounded to two decimal places. If the input number is even, calculate its cube root and return the result rounded to two decimal places.
🌐
GeeksforGeeks
geeksforgeeks.org › python-program-for-find-cubic-root-of-a-number
Python Program for Find cubic root of a number - GeeksforGeeks
July 27, 2023 - We are given a number and our task is to find the cube of this number in Python. The cube of a number is calculated by multiplying the number by itself twice. For example, if the input is 3, then the output will be 3 * 3 * 3 = 27.
🌐
AskPython
askpython.com › python-modules › numpy › numpy-cbrt
numpy. cbrt() - Return the cube root of an Element - AskPython
November 28, 2022 - Cube root of 1 is : 1.0 Cube root of 125 is : 5.0 Cube root of 1024 is : 10.079368399158984 Cube root of 27000 is : 30.0 · The output are pretty obvious and easy to understand. import numpy as np a = np.array((1 , 1000 , -27 , -99)) print("Input Array:\n",a) print("Cube root Values:\n",np.cbrt(a)) b = np.array((1024 , 216)) print("Input Array:\n",b) print("Cube root Values:\n",np.cbrt(b))
🌐
TutorialsPoint
tutorialspoint.com › article › how-can-scipy-be-used-to-calculate-the-cube-root-of-values-and-exponential-values-in-python
How can SciPy be used to calculate the cube root of values and exponential values in Python?
December 10, 2020 - HR Interview Questions · Computer Glossary · Who is Who · Python Server Side Programming Programming · SciPy provides powerful mathematical functions through its special module. Two commonly used functions are cbrt() for calculating cube roots ...
🌐
Linux Tip
linuxscrew.com › home › programming › python › python: calculating a number’s root (square/sqrt, cube), with examples
Python: Calculating a Number's Root (Square/sqrt, Cube), With Examples
September 19, 2021 - The third root is usually called the cube root. After that, there are fourth, fifth roots, and onwards – you can calculate any root, though it is less common. Calculating the square root of a number is a common task, so Python has a built-in ...