We will take a user input as a list & iterate all the values one by one with the python loop to remove negative elements from it. Print only positive values with the help of the below-given steps.
Remove negative elements from list:
Steps to solve the program
- Take a list as input.
- Using for loop and if statement check whether an element from the given list is negative or positive.
- Print only positive elements.
#Input list
list1 = [3,5,-8,0,-20,-55]
#Checking for positive values
for value in list1:
if value >= 0:
#Printing output
print(value,end=" ")
Output :
3 5 0
Related Articles
Python program to get a list of all elements which are divided by 3 and 7.
Python program to check whether the given list is palindrome or not.
Python Program to get a list of words which has vowels in the given string.
Python program to add 2 lists with extend method.
Python program to sort list data, with the sort and sorted method.
Python program to remove data from the list from a specific index using the pop method.