Python Program To Print Odd Numbers In List Example

Hello Friends,
In this blog, I will learn you how to print odd numbers in list using python. We will talk about python program to print odd numbers in list example. This article will give you simple example of how to display odd number in list using python.
In this example I am using for loop and check if num % 2 != 0. If the condition satisfies, then only print the number.
Here i will give you three example for python program to print odd numbers in list. So let's see below example:
Example 1// Python program to print odd numbers // declare list my_list = [1,2,3,4,5,6,7,8,9] // for loop for num in my_list: // checking condition if num % 2 != 0: print(num)Output:
1 3 5 7 9Example 2
// Python program to print odd numbers // declare list my_list = [1,2,3,4,5,6,7,8,9] // list of numbers num = 0 // using while loop while(num < len(my_list)): // checking condition if my_list[num] % 2 != 0: print(my_list[num]) // increment num num += 1Output:
1 3 5 7 9Example 3
// Python program to print odd numbers // declare list my_list = [1,2,3,4,5,6,7,8,9] // using list comprehension odd_nos = [num for num in my_list if num % 2 != 0] print("odd numbers is : ", odd_nos)Output:
('odd numbers is : ', [1,3,5,7,9])
It will help you....
Divyang Vadodariya
My name is Divyang Vadodariya. I'm a full-stack developer, entrepreneur and owner of RvSolutionStuff. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap ,etc from the early stage.

We are Recommending you
- How To Use Closure Using JavaScript?
- How To Use Scope Using JavaScript?
- React Native Keyboard Avoiding View Example
- How To Check Date Is Greater Than Today In JavaScript?
- React Native Alert With Two Option Example
- Drag & Drop File Uploading Using Laravel 8 Dropzone JS
- How To Get Path From Laravel Application Root?
- How To Upgrade Composer Version In Ubuntu?
- How To Extract Extension From Filename Using PHP?
- How To Write Comments In PHP Example?
Copyright © 2023 www.RVSolutionStuff.com • All Rights Reserved