Q:

Fastest way to check if a number is divisible by another in python

So I’ve been doing something with primes in python, and I’m currently using this
def isDivisible(number,divisor):
    if number % divisor == 0:
        return True
    return False

to check if a number is divisible by the divisor. 
So I was wondering if there was a faster way to do this?

A:

What about:
return (number % divisor == 0)

A:

A speed test shows that checking not() is faster than a != 0 solution:
%%timeit 
not(8 % 3)
# 19 ns ± 0.925 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)

%%timeit 
8 % 3 != 0
# 27.1 ns ± 0.929 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)

A:

I doubt there is a "faster" way of checking this. And it seems pretty simple. However, I would write your function as:
def isDivisible(number, divisor):
    return number % divisor == 0

