Check Even Number in Python

Beginner
⏱️ 7 min read
📚 Updated: May 2026
🎯 2 Code Examples
Parity

What you’ll learn

  • What an even number means, including why zero is even.
  • How to check evenness with n % 2 == 0.
  • How to print all even numbers in a range.

Overview

Even numbers are exactly those divisible by 2 without remainder. In Python, the easiest test is number % 2 == 0.

Two programs

Single number and range check.

Live preview

Quick parity check in browser.

Important note

Negative numbers also follow the same even rule.

Prerequisites

Modulo operator, if statements, and loops.

  • Know that n % 2 gives 0 or 1 for nonnegative integers.
  • Basic function creation with def.

What is an even number?

An integer is even if it can be split into pairs with nothing left over. Mathematically: n = 2 * k for some integer k.

Examples: 10, 0, and -4 are even. 11 is odd.

Evenn % 2 == 0
Oddn % 2 != 0
Zeroeven

Modulo 2 view

Even numbers are congruent to 0 modulo 2. Odd numbers are congruent to 1 modulo 2.

10

10 % 2 = 0, so 10 is even.

Intuition

8Even
Pairs
4 pairs
7Odd
Remainder
7 % 2 = 1

Takeaway: parity tells whether a number can be split into complete pairs.

Live preview

Works with positive and negative integers in safe range.

Live result
Press "Check parity" to classify.

Algorithm

Goal: return True only when number is divisible by 2.

Compute remainder

Find n % 2.

Check zero

If remainder is 0, number is even.

Use in loop

Apply same check for each value in a range.

📜 Pseudocode

Pseudocode
function is_even(n):
    return (n mod 2) == 0

function print_evens(start, end):
    for i from start to end:
        if is_even(i):
            output i
1

Check one number with modulo

Simple helper function for single value parity checking.

python
def is_even(number: int) -> bool:
    return number % 2 == 0


number = 10
if is_even(number):
    print(f"{number} is an even number.")
else:
    print(f"{number} is not an even number.")

Explanation

The function returns True when remainder by 2 is exactly zero.

2

Print evens in range [1, 10]

Reuses the same helper and prints only even values.

python
def is_even(num: int) -> bool:
    return num % 2 == 0


def print_evens_in_range(start: int, end: int) -> None:
    print(f"Even numbers in the range {start} to {end}:")
    for i in range(start, end + 1):
        if is_even(i):
            print(i, end=" ")


print_evens_in_range(1, 10)

Explanation

Inclusive range uses end + 1 in Python.

Optimization

Step by two. Start from first even value and increment by 2 when printing ranges.

Bitwise option. (n & 1) == 0 is a common parity shortcut.

Interview: explain modulo first, then mention bitwise.

❓ FAQ

An integer n is even if n can be written as 2*k for some integer k.
Yes. 0 is divisible by 2 and 0 % 2 equals 0.
Because remainder 0 means divisible by 2. It is the clearest beginner test.
Yes, (n & 1) == 0 also detects even numbers for integers.
Yes. For example, -4 % 2 is 0, so it is even.
Checking one number is O(1). Scanning a range is O(range size).

🔄 Input / output examples

Test these values in the first example.

nEven?
0Yes
10Yes
11No
-4Yes

Edge cases and pitfalls

The formula works for all integers, including negatives and zero.

Zero

n = 0

Even by definition.

Negative

Still valid

-4 % 2 == 0, so -4 is even.

Range bounds

Inclusive end

Remember range(start, end + 1).

Input

Validate types

Convert user input to integer safely before checking.

⏱️ Time and space complexity

OperationTimeExtra space
Single checkO(1)O(1)
Range scan [a, b]O(b - a + 1)O(1)

Summary

  • Use n % 2 == 0 to test evenness.
  • Zero is even, and negatives can be even too.
  • For ranges, reuse the same helper function.
Did you know?

Zero is an even number because 0 = 2 * 0. In Python, 0 % 2 == 0 is True.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful