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