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:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

The 5th prime is 11

Example #2:

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output:

The 23rd prime is 83


My Personal Notes arrow_drop_up

Coder Machine Learner Social Activist Vocalist

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.