Monday, October 6, 2025
HomeLanguagesPython | sympy.perfect_power() method

Python | sympy.perfect_power() method

With the help of sympy.perfect_power() method, we can find two integers b and e such that be is equal to the given number n.

Syntax:
perfect_power(n)

Parameter:
n – It denotes an integer.

Returns:
Returns a tuple of integers (b, e) such that be == n.

Example #1:




# import perfect_power() method from sympy
from sympy import perfect_power
  
n = 64
  
# Use perfect_power() method 
b, e = perfect_power(n) 
      
print("n = {}".format(n))
print("b = {} and e = {}.".format(b, e))
print("{}^{} == {}".format(b, e, n)) 


Output:

n = 64
b = 2 and e = 6.
2^6 == 64

Example #2:




# import perfect_power() method from sympy
from sympy import perfect_power
  
n = 64
  
# Use perfect_power() method 
b, e = perfect_power(n, big = False
      
print("n = {}".format(n))
print("b = {} and e = {}.".format(b, e))
print("{}^{} == {}".format(b, e, n)) 


Output:

n = 64
b = 8 and e = 2.
8^2 == 64
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32338 POSTS0 COMMENTS
Milvus
86 POSTS0 COMMENTS
Nango Kala
6707 POSTS0 COMMENTS
Nicole Veronica
11871 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11936 POSTS0 COMMENTS
Shaida Kate Naidoo
6825 POSTS0 COMMENTS
Ted Musemwa
7090 POSTS0 COMMENTS
Thapelo Manthata
6779 POSTS0 COMMENTS
Umr Jansen
6782 POSTS0 COMMENTS