Have a look at the Miller–Rabin primality test if a probabilistic algorithm will suffice. You could also prove a number to be prime, with for instance Elliptic Curve Primality Proving (ECPP), but it takes more effort.
A simple trial division algorithm is the following
def prime(a):
return not (a < 2 or any(a % x == 0 for x in range(2, int(a ** 0.5) + 1)))
Edit:
Here's a more educational version because the first solution is very condensed and perhaps harder to read:
from math import sqrt
def prime(a):
if a < 2: return False
for x in range(2, int(sqrt(a)) + 1):
if a % x == 0:
return False
return True
I've substituted in sqrt(a)
in place of a ** 0.5
to make things more clear. The square root is used to not look at more factors than we have to.