Thursday, September 25, 2025
HomeLanguagesPython sympy | sieve.mobiusrange() method

Python sympy | sieve.mobiusrange() method

With the help of sympy.sieve.mobiusrange() method, we can generate the mobius numbers for a given range [a, b). It returns a type generator object which can be converted to a list for further operations.

Syntax: sieve.mobiusrange(a, b)
Parameters:
a – It denotes the start of the range. It is inclusive.
b – It denotes the end of the range. It is not inclusive.
Returns: The method returns a type generator object.

Example #1:




# import sympy 
from sympy import sieve
  
# Use sieve.mobiusrange() method 
mobius_gen = sieve.mobiusrange(1, 10
mobius_list = list(mobius_gen)
      
print("Mobius numbers for the range of numbers [1, 10) : {}".format(mobius_list))  


Output:

Mobius numbers for the range of numbers [1, 10) : [1, -1, -1, 0, -1, 1, -1, 0, 0]

Example #2:




# import sympy 
from sympy import sieve
  
# Use sieve.mobiusrange() method 
mobius_gen = sieve.mobiusrange(8, 20
mobius_list = list(mobius_gen)
      
print("Mobius numbers for the range of numbers [8, 20) : {}".format(mobius_list))     


Output:

Mobius numbers for the range of numbers [8, 20) : [0, 0, 1, -1, 0, -1, 1, 1, 0, -1, 0, -1]
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32320 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6682 POSTS0 COMMENTS
Nicole Veronica
11854 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11910 POSTS0 COMMENTS
Shaida Kate Naidoo
6795 POSTS0 COMMENTS
Ted Musemwa
7071 POSTS0 COMMENTS
Thapelo Manthata
6754 POSTS0 COMMENTS
Umr Jansen
6762 POSTS0 COMMENTS