Check Odd Number in Python

Beginner
⏱️ 9 min read
📚 Updated: Aug 2026
🎯 3 Code Examples
🚀 Live Preview
Parity

What You’ll Learn

An odd integer leaves a nonzero remainder when divided by 2: n % 2 != 0. This tutorial covers a reusable helper, listing odds in a range, stepping by two, a live checker, worked Python examples, edge cases, and complexity.

Definition

Not divisible by 2

Odd integers have nonzero remainder mod 2.

Test

n % 2 != 0

One modulo check decides parity.

Zero

Even

0 % 2 = 0, so zero is not odd.

Range List

1..10

Print odds with a loop + helper.

Live Preview

Try 15 / 0 / -3

Check any integer in the browser.

O(1) Check

One compare

A single modulo decides yes or no.

Introduction

Odd numbers are integers not divisible by 2. In Python, that is a one-line test: number % 2 != 0.

Every integer is either even or odd — never both. Zero is even, so the odd check correctly returns false for 0. Negatives work the same way in Python (for example, -5 is odd).

Why it matters?

Parity checks appear constantly in interviews and everyday logic — and they are the twin of even-number tests.

Key Highlights

Modulo Test

n % 2 != 0 means odd.

Bool Helper

Keep logic separate from printing.

Zero Is Even

Odd check returns false for 0.

Step by 2

List odds without testing every n.

In short: return n % 2 != 0; reuse that helper when scanning a range.

📝 Problem & Approach

Given an integer, decide whether it is odd, and optionally list all odd values in a closed range.

python
# 15 % 2 = 1  -> odd
#  8 % 2 = 0  -> not odd (even)
#  0 % 2 = 0  -> not odd (even)

Inputs & Outputs

ItemTypeDescription
number / nintInteger to classify.
ReturnboolTrue when n % 2 != 0.
Range printtextOdd integers from start through end.

Minimal workflow

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

Method comparison

MethodIdeaNotes
Modulon % 2 != 0Interview default — clearest
Bitwise(n & 1) == 1Fine optional; explain modulo first
Step by 2range(start_odd, end+1, 2)Lists odds without testing each n

⚡ Quick Reference

GoalPattern
Check oddreturn n % 2 != 0
Check evenreturn n % 2 == 0
Messageif is_odd(n): print(...)
Scan rangefor i in range(start, end + 1):
Step by 2range(1, 11, 2)
Bit trick(n & 1) == 1

📋 Modulo vs Bitwise vs Step-2

Same parity answer — different styles and interview signals.

Modulo
n % 2 != 0

This page — clearest for beginners

Bitwise
(n & 1) == 1

Optional; mention after modulo

Step by 2
range(..., 2)

Efficient listing of odds only

Interview tip
zero is even

State the zero edge case up front

Context

When This Problem Shows Up

Reach for an odd check whenever you need nonzero remainder mod 2.

  1. Interview warm-ups

    Modulo, helpers, and zero discussion.

  2. Filtering loops

    Keep only odd indices or values.

  3. Opposite of even

    Same skill with flipped comparison.

  4. Teaching %

    First clear use of the modulo operator.

  5. Not for floats

    Parity is defined for integers.

Key benefit: one comparison that locks in modulo thinking, zero handling, and range filtering.

🔮 Live Preview

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

Try 0, 7, 22, or -3.

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

Examples Gallery

Three complete Python programs — a single-value check, odds in 1..10, and a step-by-two listing. Click View Output to reveal sample console results.

📚 Getting Started

A reusable helper and one sample value.

Example 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.")

How It Works

15 % 2 equals 1, so the helper returns True. The caller turns that boolean into a readable sentence.

⚡ Listing Odds

Reuse the same helper while scanning a range.

Example 2 — Odds in [1, 10]

Loop through the range and print values that pass the 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()

How It Works

Python range excludes the end, so use range(1, 11) to include 10. Only values that pass is_odd are printed.

Example 3 — Step by Two

Start at the first odd and increment by 2 — no per-value modulo needed.

python
def print_odds_step_by_two(start: int, end: int) -> None:
    if start % 2 == 0:
        start += 1
    print(f"Odd numbers from {start} stepping by 2 up to {end}:")
    for i in range(start, end + 1, 2):
        print(i, end=" ")
    print()


print_odds_step_by_two(1, 10)

How It Works

After aligning start to an odd value, every second integer is odd. This is useful for long ranges where you only need the odd sequence.

🧠 How the Algorithm Decides

1

Take an integer

Use a fixed value or validated input.

Input
2

Compute n % 2

Remainder when dividing by 2.

Modulo
3

Test nonzero

If remainder != 0, the number is odd.

Rule
=

Print or filter

Reuse the same helper in range loops.

🔎 Worked Walkthrough — Sample Values

Apply n % 2 != 0 to a few integers.

nn % 2Odd?
151Yes
80No
00No (even)
-51Yes
220No

Example 1 prints that 15 is an odd number.

Use Cases

Where odd-number checks show up beyond the interview prompt.

1. Interview Warm-Ups

Modulo and bool helpers.

Example: write is_odd.

2. Filtering Ranges

Print or collect only odds.

Example: 1 3 5 7 9.

3. Opposite of Even

Flip == 0 to != 0.

Example: twin of is_even.

4. Index Patterns

Process every other item.

Example: odd indices.

5. Zero Edge Talk

Show that 0 is even, not odd.

Example: 0 % 2 = 0.

6. Bridge to Palindrome

Next number-classification topic.

Example: related CTA.

Pro Tip: open with “odd means n % 2 != 0; zero is even” before writing code.

Advantages

Why the modulo-based odd check works well for beginners and interviews.

  1. 1. Tiny Logic

    One remainder decides the answer.

  2. 2. Reusable Helper

    Bool return keeps printing and logic separate.

  3. 3. Works for Negatives

    Python modulo keeps the same odd/even story.

  4. 4. Cheap

    O(1) time and space for a single check.

Pro Tip: explain modulo first; mention (n & 1) only as an optional aside.

Usage Tips

Small habits that keep odd-number solutions interview-ready.

  1. 1. Prefer a Bool Helper

    Return True/False; print in the caller.

  2. 2. Mention Zero

    Say explicitly that zero is even.

  3. 3. Watch range Endpoints

    Use end + 1 when you need an inclusive end.

  4. 4. Step by 2 for Long Lists

    Avoid testing every integer when you only need odds.

  5. 5. Lead With Modulo

    Save bitwise tricks for a follow-up comment.

Pro Tip: dry-run 15, 0, and -5 — if those three match the table, your rule is correct.

Common Pitfalls

Mistakes that commonly break odd-number programs.

  1. 1. Calling Zero Odd

    Assuming 0 fails evenness somehow.

    → 0 % 2 = 0, so zero is even.

  2. 2. Wrong Comparison

    Using == 0 when you meant odd.

    → Odd needs nonzero remainder.

  3. 3. Off-by-One range

    Missing the last value with exclusive end.

    → Use range(start, end + 1).

  4. 4. Treating Floats as Parity

    Asking if 1.5 is odd.

    → Stick to integers.

  5. 5. Skipping Negatives

    Assuming only positives can be odd.

    → Test -5 in your walkthrough.

Edge Cases

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

Zero

n = 0

Zero is even, so odd check returns false.

Negative

Still valid

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

Range

Inclusive end

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

One

n = 1

Smallest positive odd integer.

Even

Opposite parity

If not odd, it is even for integers.

Float

Decimals

Out of scope — parity is for integers.

⚖️ Facts Worth Knowing

Handy follow-ups interviewers sometimes ask.

  • Exclusive classes. Every integer is odd or even, never both.
  • Zero is even. 0 = 2×0, so it fails the odd test.
  • Successor flips. n odd ⇒ n+1 even; n even ⇒ n+1 odd.
  • Bit view. The least significant bit is 1 for odd integers.

🎯 Practice Problems

Try these variations to lock in the pattern.

1. Classify four values

  • Test 15, 0, 22, -5
  • Match the walkthrough table

2. Print 1..10 odds

  • Reproduce Example 2
  • Expect 1 3 5 7 9

3. Step-by-two version

  • Implement Example 3
  • Start odd, step 2

4. Twin even helper

  • Write is_even with == 0
  • Confirm opposite of is_odd

Notes

  • Test: n % 2 != 0.
  • Zero is even, so it is not odd.
  • Ranges: reuse the same helper in loops.
  • For long ranges, start at the first odd and increment by 2. (n & 1) == 1 also detects odd integers. Explain modulo first, then mention bitwise as optional.

Quick Takeaway: odd means n % 2 != 0; zero is even; reuse the helper in range loops.

⏱️ Time and Space Complexity

OperationTimeExtra space
is_odd(n)O(1)O(1)
Range [a, b] scanO(b - a + 1)O(1)
Step-by-2 listingO((b - a) / 2)O(1)

One comparison is constant time; listing grows with how many numbers you visit.

Wrap Up

🎉 Conclusion

Checking an odd number is a one-line rule: return n % 2 != 0. Keep the helper boolean, remember that zero is even, and reuse the same test when scanning ranges or stepping by two.

Practice the three examples above, then continue to checking palindrome numbers.

is_odd(n) returns n % 2 != 0; zero is not odd.

💡 Best Practices

✅ Do

  • Use n % 2 != 0
  • Keep a bool helper
  • State that zero is even
  • Test negatives too
  • Step by 2 for long odd lists

❌ Don’t

  • Call zero odd
  • Use == 0 for odd checks
  • Forget range end + 1
  • Apply parity to floats
  • Lead with bitwise only

Key Takeaways

Knowledge Unlocked

Five things to remember about odd numbers

Classify parity the interview-friendly way.

5
Core concepts
? 02

Helper

Return bool

Pattern
0 03

Zero

Even, not odd

Edge
2 04

Step

range(..., 2)

List
O 05

Cost

O(1) check

Analysis

❓ Frequently Asked Questions

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).
Yes. In Python, -5 % 2 equals 1, so -5 is odd under the same test.
Start at the first odd value and step by 2 instead of testing every integer.
Even uses n % 2 == 0. Odd uses nonzero remainder — opposite parity.

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.

Continue to Palindrome Number

Learn how to check whether a number reads the same forwards and backwards in Python.

Palindrome number tutorial →

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