Categories
Python Answers

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

Spread the love

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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *