def isPrime(n):
    if n < 2:
        return False
for number in islice(count(2), int(sqrt(n) - 1)):
    if not n % number:
        return False
return True
Checking if a number is a prime number in Python