A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/python-program-to-print-odd-numbers-in-a-list/ below:

Print odd numbers in a List - Python

Print odd numbers in a List - Python

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:


Python program to Print Odd Numbers in a List


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4