Python Program to Print all Odd Numbers in a Range
Last Updated :
28 Oct, 2025
Given a range of numbers, the task is to print all odd numbers within that range. An odd number is any number that is not divisible by 2 (i.e., gives remainder 1 when divided by 2).
For example:
Range: 1 to 10 -> Odd numbers = 1, 3, 5, 7, 9
Range: 5 to 15 -> Odd numbers = 5, 7, 9, 11, 13, 15
Let’s explore different methods to print all odd numbers within a range.
Using range() with Step
This method directly generates odd numbers using range() function with a step value of 2. By starting from the first odd number, it automatically skips all even numbers, making it highly efficient.
Python
start = 1
end = 10
for num in range(1, end + 1, 2):
print(num)
Explanation:
- range(1, end + 1, 2) starts at 1 and jumps by 2 each time.
- Only odd numbers are generated no need for conditional checks.
Using Bitwise AND (&) Operator
Bitwise AND operator is useful when we need to check if a number is odd or even. The binary representation of an odd number always ends in 1, while an even number ends in 0. So, we can check if a number is odd by using num & 1.
Python
start = 1
end = 10
for num in range(start, end + 1):
if num & 1:
print(num)
Explanation:
- The & operator compares the last bit of the number.
- If it’s 1, number is odd.
Using List Comprehension
Here we creates a list of odd numbers in one line using list comprehension with a conditional check num% 2 ! = 0.
Python
start = 1
end = 10
res = [num for num in range(start, end + 1) if num % 2 != 0]
print(res)
Using for loop with if condition
This is the basic approach. It iterates through the range and checks if each number gives a remainder of 1 when divided by 2.
Python
for num in range(1, 11):
if num % 2 != 0:
print(num)
Python Program to Print all Odd Numbers in a Range
Explore
Python Fundamentals
Python Data Structures
Advanced Python
Data Science with Python
Web Development with Python
Python Practice