What is sympy.prevprime() in Python?
What is sympy library?
sympy is a library used for symbolic mathematics.
pip can be used to install sympy. You can refer to the following command.
pip install sympy
The prevprime method
The prevprime method returns the largest prime number that is less than the given number. The given number has to be a positive number.
Syntax
sympy.prevprime(n)
Parameters
n: This can be any positive number.
Return value
The method returns the largest prime number that is less than the given number.
Code
# imports sympy libraryimport sympy# declares variable n with value = 5n = 5# prints the largest prime number# less than the given number nprint("sympy.prevprime(%s) = %s" % (n, sympy.prevprime(n)))
Code explanation
- Line 1: We import the
sympypackage. - Line 3: We define
n. - Line 5: We obtain the largest prime number less than
nusing thesympy.prevprime()method.