Friday, October 24, 2025
HomeLanguagesPython sympy | sieve.extend_to_no() method

Python sympy | sieve.extend_to_no() method

With the help of sympy.sieve.extend_to_no() method, we can extend the sieve to include the ith prime number.
Note: The list is extended by 50% if it is too short, so it is likely that it will be longer than requested.

Syntax: sieve.extend_to_no(i)
Parameter:
i – It denotes that the sieve is extended to include the ith prime number.
Returns: The method does not return anything.

Example #1:




# import sympy 
from sympy import sieve
  
# Use sieve.extend_to_no() method 
sieve.extend_to_no(15
prime_list = sieve._list
      
print("Prime Numbers up to 15th prime : {}".format(prime_list))  


Output:

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

Example #2:




# import sympy 
from sympy import sieve
  
# Use sieve.extend_to_no() method 
sieve.extend_to_no(20
prime_list = sieve._list
      
print("Prime Numbers up to 15th prime : {}".format(prime_list))   


Output:

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

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS