+4 votes
in Programming Languages by (20.2k points)
Is there any function in Python to check if the given number is a prime number?

1 Answer

0 votes
by (35.8k points)

The sympy module has function isprime() that checks whether the number is prime or not and returns True/False. 

Here is the code that can be used:

>>> from sympy import isprime
>>> isprime(31)
True
>>> isprime(23)
True
>>> isprime(4)
False
>>> isprime(1)
False
>>>

...