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

1 Answer

+1 vote
by (42.1k 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
>>>

...