# How To Check If A Number Is Divisible By Another Number In Python

To check if a number is divisible by another number in Python, there are three solutions we have effectively tested. Follow the article to better understand.

## Check if a number is divisible by another number in Python

The division is a mathematical concept in which divisibility and remainder are divided. Divisibility is proved true when the remainder after dividing two numbers is 0. Let’s follow some methods below to check if a number is divisible by another number in Python.

### Using the % modulus operator to check for divisibility

Use the % operator module to get the remainder from dividing a number by a number. Then use the ‘==’ operator to compare the resulting remainder with 0. If the operation returns ‘true’, then it is divisibility, and the operation returns ‘False’ is not divisible.

Example 1:

def isDivisible(number1, number2):
resultOfDiv = number1 % number2

if resultOfDiv == 0:
print(f"{number1} is divisible by {number2}")
else:
print(f"{number1} is not divisible by {number2}")

isDivisible(10, 2)
isDivisible(10, 3)

Output:

10 is divisible by 2
10 is not divisible by 3

### Using the Lambda function with filter()

In Python, a hidden function is defined for which the function has no name. Implicit functions are defined with the keyword lambda. So ‘lambda functions’ are also known as anonymous functions.

Syntax:

lambda arguments: expression

‘Lambda functions’ can have many arguments but only one expression. ‘Lambda functions’ can be used anywhere function objects are required.

‘Lambda functions’ is often combined with built-in functions such as filter(), map(),….

The filter() function argument is a function or a list. Use the filter() function to check for divisibility.

Example:

myList = [1, 5, 4, 6, 8, 11, 3, 12]

# Use the filter() function to check for divisibility
result = list(filter(lambda x: (x % 2 == 0), myList))
print(result)

Output:

[4, 6, 8, 12]

In the above example, the filter() function has the effect of filtering out even numbers from the value returned by the lambda function.

### Using the Lambda function with map()

The map() function also accepts a function or a list as an argument. We can also use the map() function to check divisibility or not.

Example:

myList = [1, 5, 4, 6, 8, 11, 3, 12]
result = list(map(lambda x: x % 2, myList))
print(result)

Output:

[1, 1, 0, 0, 0, 1, 1, 0]

The map() function returns the remainder of the division. If the remainder is 0, then the number is divisible by 2.