Saturday, May 9, 2026
HomeLanguagesPython | sympy.prime() method

Python | sympy.prime() method

With the help of sympy.prime() method, we can find the nth prime, with the primes indexed as prime(1) = 2, prime(2) = 3, etc.

Syntax: prime(n)

Parameter:
n – It denotes the nth prime number.

Returns: Returns the nth prime number.

Example #1:




# import sympy 
from sympy import prime
  
n = 5
  
# Use prime() method 
nth_prime = prime(n) 
      
print("The {}th prime is {}".format(n, nth_prime))  


Output:

The 5th prime is 11

Example #2:




# import sympy 
from sympy import prime
  
n = 23
  
# Use prime() method 
nth_prime = prime(n) 
      
print("The {}rd prime is {}".format(n, nth_prime))        


Output:

The 23rd prime is 83
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32514 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6892 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12107 POSTS0 COMMENTS
Shaida Kate Naidoo
7016 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6975 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS