Friday, October 24, 2025
HomeLanguagesPython | sympy.trailing() method

Python | sympy.trailing() method

With the help of sympy.trailing() method, we can count the number of trailing zero digits in the binary representation of a given number, i.e. determine the largest power of 2 that divides that number.

Syntax:
trailing(n)

Parameter:
n – It denotes the number for which the largest power of 2 that divides that number is determined.

Returns:
Returns the largest power of 2 that divides the given number.

Example #1:




# import trailing() method from sympy
from sympy.ntheory.factor_ import trailing
   
n = 64
   
# Use trailing() method 
trailing_n = trailing(n) 
       
print("The largest power of 2 that divides {} is 2^{}.".
      format(n, trailing_n))


Output:

The largest power of 2 that divides 64 is 2^6.

Example #2:




# import trailing() method from sympy
from sympy.ntheory.factor_ import trailing
  
n = 130
  
# Use trailing() method 
trailing_n = trailing(n) 
      
print("The largest power of 2 that divides {} is 2^{}.".
      format(n, trailing_n))


Output:

The largest power of 2 that divides 130 is 2^1.
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS