Thursday, December 18, 2025
HomeLanguagesPython sympy | sieve.extend() method

Python sympy | sieve.extend() method

With the help of sympy.sieve.extend() method, we can grow the sieve to cover all the prime numbers less than equal to a given natural number.

Syntax: sieve.extend(N)
Parameter:
N – It denotes the number up to which the sieve is extended.
Returns: The function does not return anything.

Example #1:




# import sympy 
from sympy import sieve
  
# Use sieve.extend() method 
sieve.extend(50
prime_list = sieve._list
      
print("Prime Numbers up to 50 : {}".format(prime_list))  


Output:

Prime Numbers up to 50 : array('l', [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47])

Example #2:




# import sympy 
from sympy import sieve
  
# Use sieve.extend() method 
sieve.extend(100
prime_list = sieve._list
      
print("Prime Numbers up to 100 : {}".format(prime_list))  


Output:

Prime Numbers up to 100 : array('l', [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])
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32455 POSTS0 COMMENTS
Milvus
108 POSTS0 COMMENTS
Nango Kala
6823 POSTS0 COMMENTS
Nicole Veronica
11958 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12035 POSTS0 COMMENTS
Shaida Kate Naidoo
6958 POSTS0 COMMENTS
Ted Musemwa
7203 POSTS0 COMMENTS
Thapelo Manthata
6910 POSTS0 COMMENTS
Umr Jansen
6890 POSTS0 COMMENTS