Contents
Python Program to Check if Number is Even
To check if given number is even or not in Python, we can divide the given number by 2 and find the remainder. If the remainder is equal to zero, then the given number is even, or else not.
If n
is given number, then the boolean condition to check if n
is even is
n % 2 == 0
Example
In the following program, we take an integer value in n
, and check if this number is even or not.
Python Program
n = 10
if ( n % 2 == 0 ) :
print(f'{n} is even number.')
else :
print(f'{n} is not even number.')
Run Summary
In this tutorial of Python Examples, we learned how to check if a given number is an even number or not.
Related Tutorials
- How to Swap Two Numbers in Python?
- How to Get Number of Elements in Pandas DataFrame?
- Python – Sum of Two Numbers
- How to Get Number of Axes in Pandas DataFrame?
- Python – Largest of Three Numbers
- Python String – Find the number of overlapping occurrences of a substring
- Python – Smallest of Three Numbers
- Reverse a Number in Python
- Python – Factorial of a Number
- Numpy sqrt() – Find Square Root of Numbers