Python Program Find Positive Number From List

Python

Nicesnippets

243

10-08-2021


Hello Friends,

In this blog, I am going to show you how to get positive number from list in python. We will talk about python program to print positive numbers in list example. This article will give you simple example of how to display positive number in list using python.

In this example I am using for loop and check if num > 0. If the condition satisfies, then only print the number.

Here i will give you two example for python program to print positive numbers in list. So let's see below example:

Example 1


# Python program to print positive numbers from list

# list of numbers

list1 = [5, 32, -3, -68, 0, 8, 6, -99]

# iterating each number in list

for num in list1:

if num >= 0:

print(num)

Output :

5

32

0

8

6

Example 2

# Python program to print positive numbers from list

# list of numbers

list1 = [5, 32, -3, -68, 0, 8, 6, -99]

# iterating each number in list

pos_nos = [num for num in list1 if num >= 0]

print(pos_nos)

Output :

[5, 32, 0, 8, 6]

It will help you....


Recommended Posts