+

Python | sympy.prime () method

Using the sympy.prime () method, we can find the nth prime whose primes are 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 the prime () method 

nth_prime = prime (n) 

 

print ( "The {} th prime is {}" . format (n, nth_prime)) 

Exit:

 The 5th prime is 11 

Example # 2:

# import sympy

from sympy import prime

 

n = 23

  
# Use the prime () method

nth_prime = prime (n) 

 

print ( "The {} rd prime is {}" . format (n, nth_prime)) 

Exit:

 The 23rd prime is 83 
Get Solution for free from DataCamp guru