How to Find the Even Number or Odd Number in Python

Last Updated on May 16, 2024 by Roshan Parihar

To find the even number or odd number in Python, use the % (modulo) operator with the Python if conditional statement.

The even number is the multiple of 2 and the odd is not a multiple of 2. Let’s find them with the examples given below.

Find The Even Number in Python

An even number is a number that is perfectly divisible by 2 without any remainder. If you want to find whether the number is even or not, you have to use the % (modulo) operator as given below.

Examples 1

Output

The number is an 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.

Check the Odd Numbers in Python

An odd number is not a perfect divisible of 2 and gives some remainder number also. If you want to check the odd numbers in Python, you have to use the % (modulo) operator as given below.

Examples 2

Output

The number is odd.

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 whether the number is 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.

Examples 3

Output

The number is odd.

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

One reply on “How to Find the Even Number or Odd Number in Python”

Comments are closed.