Python | simpy.primerange() method

In simpy module, we can get the a 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:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python program to get prime number range 
# using sympy.primerange() method
  
# importing sympy module
from sympy import *
  
# calling primerange function on differnet numbers
list(primerange(7, 30))
list(primerange(0, 100))

chevron_right


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:

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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))

chevron_right


Output:

[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.