SymPy
?SymPy
is a library for symbolic mathematics in Python.
We use pip
to install SymPy
with the following command:
pip install sympy
prime
methodThe prime
method gets the n
th prime number, starting with 2
as the first prime number. n
must be a positive integer exclusive of zero (0
), or else the method throws a ValueError
.
sympy.prime(n)
n
: It is the prime number that should be greater than 0.The method returns the n
th prime number.
from sympy import primen = 5print("prime(%s) = %s" % (n, prime(n)))
prime
function from the SymPy
package.n
.n
th prime number using the prime(n)
function.