In Python, we can check if a number is divisible by 2 very easily with the Python built in remainder operator **%**. If the remainder of a number after dividing by 2 is 0, then the number is divisible by 2.

```
def isDivisibleBy2(num):
if (num % 2) == 0:
return True
else:
return False
print(isDivisibleBy2(10))
print(isDivisibleBy2(15))
#Output:
True
False
```

When working with numbers in Python, it can be useful to know if the numbers you are working with are divisible by another number.

We can use the Python built in remainder operator **%** to get the remainder of a number after division.

To determine if a number is divisible by 2 using Python, we divide by 2. If the remainder after division is 0, then the number is the number is divisible by 2. If it is not 0, then the number is not divisible by 2.

Below is a function which will check if a number is divisible by 2 in Python.

```
def isDivisibleBy2(num):
if (num % 2) == 0:
return True
else:
return False
print(isDivisibleBy2(10))
print(isDivisibleBy2(15))
#Output:
True
False
```

## How to Check if a Number is Even or Odd Using Python

In Python, we can check if a number is even or odd very easily with the Python built in remainder operator **%**. If the remainder of a number after dividing by 2 is 0, then the number is even. If not, the number is odd.

```
def isEven(num):
if (num % 2) == 0:
return True
else:
return False
print(isEven(10))
print(isEven(15))
#Output:
True
False
```

## How to Determine if a Number is Divisible by Another Number

Using the Python remainder operator **%**, we can determine if a number is divisible by any other number.

For example, if we want to determine if a number is divisible by 3, just put 3 after the **%** operator.

```
def isDivisibleBy3(num):
if (num % 3 == 0:
return True
else:
return False
print(isDivisibleBy3(10))
print(isDivisibleBy3(15))
#Output:
False
True
```

Hopefully this article has been useful for you to understand how to determine if a number is divisible by 2 in Python.

## Leave a Reply