Thursday, October 9, 2025
HomeLanguagesPython | sympy.primerange() method

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




# Python program to get prime number range
# using sympy.primerange() method
 
# importing sympy module
from sympy import *
 
# calling primerange function on different numbers
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




# Python program to get the range prime number
# using sympy.primerange() method
 
# importing sympy module
import sympy.ntheory as nt
 
# calling primerange function on range
list(nt.primerange(2, 31))


Output: 

[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32342 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6712 POSTS0 COMMENTS
Nicole Veronica
11876 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11937 POSTS0 COMMENTS
Shaida Kate Naidoo
6833 POSTS0 COMMENTS
Ted Musemwa
7092 POSTS0 COMMENTS
Thapelo Manthata
6786 POSTS0 COMMENTS
Umr Jansen
6789 POSTS0 COMMENTS