-3

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.

  • 1
    If your numbers are large, you can use [sympy's isprime](https://docs.sympy.org/latest/modules/ntheory.html#sympy.ntheory.primetest.isprime) – JohanC Aug 13 '20 at 14:51

1 Answers1

0

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.

Mihai
  • 831
  • 6
  • 13