Check Odd Number in Python

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

What you’ll learn

  • What odd means when dividing by 2.
  • A clean is_odd helper using n % 2 != 0.
  • How to print odd numbers in a fixed range.

Overview

Odd numbers are integers not divisible by 2. In Python, you can classify parity in one line with modulo.

Two programs

Single value check and range printing.

Live preview

Try your own integer and instantly see the result.

Important fact

Zero is even, so it is not odd.

Prerequisites

Modulo operator %, if conditions, and for loops.

  • Basic Python syntax with def and print.
  • Understanding that modulo gives remainder after division.

What is an odd number?

An odd number is an integer that cannot be divided by 2 evenly. It always leaves a remainder.

In Python, parity checks are easy and readable using n % 2.

Odd n % 2 != 0
Even n % 2 == 0
Zero even

Remainder mod 2

Odd integers are those that are not divisible by 2. In modular arithmetic language, odd numbers have nonzero remainder when divided by 2.

15

15 % 2 = 1, so 15 is odd.

Quick examples

9 Odd
Remainder
9 % 2 = 1
8 Even
Remainder
8 % 2 = 0

Takeaway: odd and even are opposite parity classes.

Live preview

Uses JavaScript safe integers but follows the same odd-number rule as Python examples.

Try 0, 7, 22, or -3.

Live result
Press "Is it odd?" to see the verdict.

Algorithm

Goal: decide if a number is odd and print odd values in a range.

Compute modulo

Calculate n % 2.

Check nonzero remainder

If remainder is not 0, number is odd.

Loop through range

Use the same check for each integer from start to end.

📜 Pseudocode

Pseudocode
function is_odd(n):
    return (n mod 2) != 0

function print_odds(start, end):
    for i from start to end:
        if is_odd(i):
            output i
1

Check one number

Simple helper using modulo to classify a single value.

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


number = 15
if is_odd(number):
    print(f"{number} is an odd number.")
else:
    print(f"{number} is not an odd number.")

Explanation

If remainder by 2 is nonzero, the function returns True.

2

Odds in [1, 10]

Loop through the range and print values that pass odd check.

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


def print_odds_from_1_to_10() -> None:
    print("Odd numbers in the range 1 to 10:")
    for i in range(1, 11):
        if is_odd(i):
            print(i, end=" ")


print_odds_from_1_to_10()

Explanation

Python range end is exclusive, so use range(1, 11) to include 10.

Notes

Step by two. For long ranges, start at first odd and increment by 2.

Bit trick. (n & 1) == 1 also detects odd integers.

Interview tip: explain modulo first, then mention bitwise as optional.

❓ FAQ

It is an integer that is not divisible by 2. For nonnegative values, this means remainder 1 when divided by 2.
No. Zero is even, because 0 % 2 equals 0.
Because remainder by 2 directly tells parity. Nonzero remainder means odd.
Yes, for integers. Exactly one of odd/even is true.
Yes for integer bit checks, but modulo is usually clearer for beginners.
Single check is O(1). Scanning a range is O(range size).

🔄 Input / output examples

Use this quick table to check your understanding.

nOdd?
0No (even)
15Yes
22No
-5Yes

Edge cases and pitfalls

Odd/even classification works for positive, zero, and negative integers.

Zero

n = 0

Zero is even, so odd check returns false.

Negative values

Still valid

Example: -5 % 2 != 0, so -5 is odd.

Range endpoint

Inclusive ranges

Remember Python range excludes end, so use end + 1.

⏱️ Time and space complexity

OperationTimeExtra space
is_odd(n)O(1)O(1)
Range [a, b] scanO(b - a + 1)O(1)

Summary

  • Test: n % 2 != 0.
  • Zero is even, so it is not odd.
  • Ranges: reuse same helper in loops.
Did you know?

Every whole number is either even or odd—never both. Zero is even, so the test n % 2 != 0 correctly says zero is not odd.

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