pythondivision

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


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?


Solution

  • What about:

    return (number % divisor == 0)