检查数字是否可以在python中被另一个整除的最快方法 [英] Fastest way to check if a number is divisible by another in python

查看:138
本文介绍了检查数字是否可以在python中被另一个整除的最快方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我一直在用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?

推荐答案

那:

return (number % divisor == 0)

这篇关于检查数字是否可以在python中被另一个整除的最快方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆