How To Check If The Number Is Even Or Odd In Python

In this tutorial, learn how to check if the number is even or odd using Python. The short answer is to use the % (modulo) operator with the Python if conditional statement.

The even number is the multiple of 2 and the odd is not multiple of 2. Find the type of any number whether it is even or odd using method here. In the end, you will also find the other methods to find the number is even or odd in Python.

Check If The Number Is Even Using Python

An even number is a number which is perfectly divisible by 2 without any remainder. It divides the number by 2 and gets the remainder to check if equals to 0. If the remainder is zero(0), it confirms the number is even.

If you want to find the number is even or not, you have to use the % (modulo) operator.

Output

The number is even number.

The above example finds the number which is even using the Python %(modulo) operator. You can change the above code as per your requirement to find the number if even.

Bonus: download a Free Python cheat sheet that will show you 20+ most important examples to learn in Python.

Find Out If the Given Number is Odd Using Python

An odd number is not a perfect divisible of 2 and gives some remainder number also. If the number divides by 2 and gives a remainder which does not equal to zero(0). Then, it is the odd number in Python. Below is the simple method you can use to find the number if it is odd or not.

Output

The number is odd number.

The above output shows that the given number is odd. You can also check your number if it is odd or not using the above example.

How To Check If The Number Is Even Or Odd In Python

Other Methods To Check Whether The Number Is Odd Or Even in Python

If you want to use other methods to find the number if even or odd. You can use & (bitwise) operator of Python to check. You have to use the below-given method to get the type in the output.

Using Bitwise Operator in Python
To find your number, you have to use the bitwise operator with the if statement.

Output

The number is odd number.

The above output shows that the given number is odd using a bitwise operator. You can also check the even number whether it is even or not using the same method. Just put your number in the above example and find its type in the output.

DOWNLOAD Free PYTHON CHEAT SHEET

I hope you like this post of how to find the number is odd or even using Python.

One reply on “How To Check If The Number Is Even Or Odd In Python”

Comments are closed.