With the help of sympy.sieve.primerange() method, we can generate all prime 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.primerange(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.primerange() method prime_gen = sieve.primerange( 1 , 10 ) prime_list = list (prime_gen) print ( "Prime numbers for the range of numbers [1, 10) : {}" . format (prime_list)) |
Output:
Prime numbers for the range of numbers [1, 10) : [2, 3, 5, 7]
Example #2:
# import sympy from sympy import sieve # Use sieve.primerange() method prime_gen = sieve.primerange( 8 , 50 ) prime_list = list (prime_gen) print ( "Prime numbers for the range of numbers [8, 50) : {}" . format (prime_list)) |
Output:
Prime numbers for the range of numbers [8, 50) : [11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]