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

1 Answer

+2 votes
by (349k points)
selected by
 
Best answer

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
>>>


...