I want to find out if a number a prime number. This can I do with this code:
def is_prime(a):
return all(a % i for i in range(2, a))
My question is whether python provides a function that checks if a number a prime number.
I want to find out if a number a prime number. This can I do with this code:
def is_prime(a):
return all(a % i for i in range(2, a))
My question is whether python provides a function that checks if a number a prime number.
Unfortunately no, it does not have a builtin function, but you can do better with your code. First, you can improve the range to be from (2, sqrt(a) + 1)
it will reduce the number of elements you check by a lot.