Python | sympy.primerange() method
In the sympy module, we can get the list of all prime numbers in the range [a, b) using sympy.primerange() function.
Syntax: sympy.primerange()
Parameter: range a and b
Return: a list of all primes in given range
Code #1:
Python3
from sympy import *
list (primerange( 7 , 30 ))
list (primerange( 0 , 100 ))
|
Output:
[7, 11, 13, 17, 19, 23, 29]
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
Code #2:
Python3
import sympy.ntheory as nt
list (nt.primerange( 2 , 31 ))
|
Output:
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
Last Updated :
08 Feb, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...