Menu Close

How to check whether a number is divisible by another number with Python?

Sometimes, we want to check whether a number is divisible by another number with Python.

In this article, we’ll look at how to check whether a number is divisible by another number with Python.

How to check whether a number is divisible by another number with Python?

To check whether a number is divisible by another number with Python, we can use the modulo operator.

For instance, we write

n % k == 0

to check if n is evenly divisible by k.

Conclusion

To check whether a number is divisible by another number with Python, we can use the modulo operator.

Posted in Python, Python Answers