Definition
Not divisible by 2
Odd integers have nonzero remainder mod 2.
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.
Not divisible by 2
Odd integers have nonzero remainder mod 2.
n % 2 != 0
One modulo check decides parity.
Even
0 % 2 = 0, so zero is not odd.
1..10
Print odds with a loop + helper.
Try 15 / 0 / -3
Check any integer in the browser.
One compare
A single modulo decides yes or no.
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).
Parity checks appear constantly in interviews and everyday logic — and they are the twin of even-number tests.
n % 2 != 0 means odd.
Keep logic separate from printing.
Odd check returns false for 0.
List odds without testing every n.
In short: return n % 2 != 0; reuse that helper when scanning a range.
Given an integer, decide whether it is odd, and optionally list all odd values in a closed range.
# 15 % 2 = 1 -> odd
# 8 % 2 = 0 -> not odd (even)
# 0 % 2 = 0 -> not odd (even) | Item | Type | Description |
|---|---|---|
number / n | int | Integer to classify. |
| Return | bool | True when n % 2 != 0. |
| Range print | text | Odd integers from start through end. |
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 | Idea | Notes |
|---|---|---|
| Modulo | n % 2 != 0 | Interview default — clearest |
| Bitwise | (n & 1) == 1 | Fine optional; explain modulo first |
| Step by 2 | range(start_odd, end+1, 2) | Lists odds without testing each n |
| Goal | Pattern |
|---|---|
| Check odd | return n % 2 != 0 |
| Check even | return n % 2 == 0 |
| Message | if is_odd(n): print(...) |
| Scan range | for i in range(start, end + 1): |
| Step by 2 | range(1, 11, 2) |
| Bit trick | (n & 1) == 1 |
Same parity answer — different styles and interview signals.
n % 2 != 0This page — clearest for beginners
(n & 1) == 1Optional; mention after modulo
range(..., 2)Efficient listing of odds only
zero is evenState the zero edge case up front
Reach for an odd check whenever you need nonzero remainder mod 2.
Modulo, helpers, and zero discussion.
Keep only odd indices or values.
Same skill with flipped comparison.
First clear use of the modulo operator.
Parity is defined for integers.
Key benefit: one comparison that locks in modulo thinking, zero handling, and range filtering.
Uses JavaScript safe integers but follows the same odd-number rule as the Python examples.
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.
A reusable helper and one sample value.
Simple helper using modulo to classify a single value.
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.") 15 % 2 equals 1, so the helper returns True. The caller turns that boolean into a readable sentence.
Reuse the same helper while scanning a range.
Loop through the range and print values that pass the odd check.
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() Python range excludes the end, so use range(1, 11) to include 10. Only values that pass is_odd are printed.
Start at the first odd and increment by 2 — no per-value modulo needed.
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) 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.
Use a fixed value or validated input.
Remainder when dividing by 2.
If remainder != 0, the number is odd.
Reuse the same helper in range loops.
Apply n % 2 != 0 to a few integers.
| n | n % 2 | Odd? |
|---|---|---|
15 | 1 | Yes |
8 | 0 | No |
0 | 0 | No (even) |
-5 | 1 | Yes |
22 | 0 | No |
Example 1 prints that 15 is an odd number.
Where odd-number checks show up beyond the interview prompt.
Modulo and bool helpers.
Example: write is_odd.
Print or collect only odds.
Example: 1 3 5 7 9.
Flip == 0 to != 0.
Example: twin of is_even.
Process every other item.
Example: odd indices.
Show that 0 is even, not odd.
Example: 0 % 2 = 0.
Next number-classification topic.
Example: related CTA.
Pro Tip: open with “odd means n % 2 != 0; zero is even” before writing code.
Why the modulo-based odd check works well for beginners and interviews.
One remainder decides the answer.
Bool return keeps printing and logic separate.
Python modulo keeps the same odd/even story.
O(1) time and space for a single check.
Pro Tip: explain modulo first; mention (n & 1) only as an optional aside.
Small habits that keep odd-number solutions interview-ready.
Return True/False; print in the caller.
Say explicitly that zero is even.
Use end + 1 when you need an inclusive end.
Avoid testing every integer when you only need odds.
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.
Mistakes that commonly break odd-number programs.
Assuming 0 fails evenness somehow.
→ 0 % 2 = 0, so zero is even.
Using == 0 when you meant odd.
→ Odd needs nonzero remainder.
Missing the last value with exclusive end.
→ Use range(start, end + 1).
Asking if 1.5 is odd.
→ Stick to integers.
Assuming only positives can be odd.
→ Test -5 in your walkthrough.
Odd/even classification works for positive, zero, and negative integers.
Zero is even, so odd check returns false.
Example: -5 % 2 != 0, so -5 is odd.
Remember Python range excludes end, so use end + 1.
Smallest positive odd integer.
If not odd, it is even for integers.
Out of scope — parity is for integers.
Handy follow-ups interviewers sometimes ask.
Try these variations to lock in the pattern.
n % 2 != 0.(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.
| Operation | Time | Extra space |
|---|---|---|
is_odd(n) | O(1) | O(1) |
Range [a, b] scan | O(b - a + 1) | O(1) |
| Step-by-2 listing | O((b - a) / 2) | O(1) |
One comparison is constant time; listing grows with how many numbers you visit.
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.
n % 2 != 0Classify parity the interview-friendly way.
n % 2 != 0
RuleReturn bool
PatternEven, not odd
Edgerange(..., 2)
ListO(1) check
AnalysisEvery whole number is either even or odd—never both. Zero is even, so the test n % 2 != 0 correctly says zero is not odd.
Learn how to check whether a number reads the same forwards and backwards in Python.
8 people found this page helpful