Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
Print odd numbers in a List - Python
Next article icon

Print odd numbers in a List - Python

Last Updated : 14 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

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) 

Output
15 23 37 51 5 

Explanation:

  • Loops through list a.
  • For each element i, checks if i % 2 != 0 (i.e., if the number is odd).
  • If the condition is true then print the odd number.

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:

  • filter() function takes two arguments: a lambda function (lambda x: x % 2 != 0) that checks if the number is odd and the iterable 'a'.
  • The result is a filter object which we convert to a list and print.

Related Articles:

  • Python For Loops
  • List Comprehension in Python
  • filter() in python

Next Article
Print odd numbers in a List - Python

S

Shivam_k
Improve
Article Tags :
  • Python
  • Python Programs
  • Computer Science Fundamentals
  • DSA
  • python-list
  • Python list-programs
Practice Tags :
  • python
  • python-list

Similar Reads

    Print Numbers in an Interval - Python
    In this article, we are going to learn how to print numbers within a given interval in Python using simple loops, list comprehensions, and step-based ranges.For Example:Input : i = 2, j = 5Output : 2 3 4 5Input : i = 10, j = 20 , s = 2Output : 10 12 14 16 18 20Let’s explore different methods to prin
    2 min read
    Python program to print positive numbers in a list
    In this article, we will explore various methods to o print positive numbers in a list. The simplest way to do is by using for loop function. Using LoopThe most basic method for printing positive numbers is to use a for loop to iterate through the list and check each element.Pythona = [-10, 15, 0, 2
    1 min read
    Print all Strong Numbers in Given List - Python
    The task of printing all Strong numbers from a given list in Python involves iterating through the list and checking each number based on its digit factorial sum. A Strong number is a number whose sum of the factorials of its digits equals the number itself. For example, given a list a = [145, 375,
    3 min read
    Python program to print even numbers in a list
    Getting even numbers from a list in Python allows you to filter out all numbers that are divisible by 2. For example, given the list a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], you might want to extract the even numbers [2, 4, 6, 8, 10]. There are various efficient methods to extract even numbers from a li
    3 min read
    Print a List of Tuples in Python
    The task of printing a list of tuples in Python involves displaying the elements of a list where each item is a tuple. A tuple is an ordered collection of elements enclosed in parentheses ( ), while a list is an ordered collection enclosed in square brackets [ ].Using print()print() function is the
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences