Print odd numbers in a List Python (original) (raw)

Last Updated : 11 Jul, 2025

We are given a list and our task is to print all the odd numbers from it. This can be done using different methods like a simple loop, list comprehension, or the filter() function. **For example, if the input is [1, 2, 3, 4, 5], the output will be [1, 3, 5].

Using Loop

The most basic way to print odd numbers in a list is to use a for loop with **if conditional check to identify odd numbers.

Python `

a = [10, 15, 23, 42, 37, 51, 62, 5]

for i in a: if i % 2 != 0: print(i)

`

**Explanation:

Using List Comprehension

List comprehension is similar to the for loop method shown above but offers a more concise way to filter odd numbers from a list.

Python `

a = [10, 15, 23, 42, 37, 51, 62, 5]

res = [i for i in a if i % 2 != 0]

print(res)

`

Output

[15, 23, 37, 51, 5]

**Explanation: This **list comprehension filters all elements in a where **i % 2 != 0 (i.e., the number is odd).

Using filter() Function

The **filter() function can also be used to filter out odd numbers. The filter() function applies a function to each item in the iterable and returns a filter object containing only those items where the function returns **True.

Python `

a = [10, 15, 23, 42, 37, 51, 62, 5]

res = filter(lambda x: x % 2 != 0, a)

print(list(res))

`

Output

[15, 23, 37, 51, 5]

**Explanation:

**Related Articles: