
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Python program to print negative numbers in a list
In this article, we will learn about the solution and approach to solve the given problem statement.
Problem statement
Given a list iterable, we need to print all the negative numbers in the list.
Here we will be discussing three approaches for the given problem statement.
Approach 1 − Using enhanced for loop
Example
list1 = [-11,23,-45,23,-64,-22,-11,24] # iteration for num in list1: # check if num < 0: print(num, end = " ")
Output
-11 -45 -64 -22 -11
Approach 2 − Using filter & lambda function
Example
list1 = [-11,23,-45,23,-64,-22,-11,24] # lambda exp. no = list(filter(lambda x: (x < 0), list1)) print("Negative numbers in the list: ", no)
Output
Negative numbers in the list: [-11 -45 -64 -22 -11]
Approach 3 − Using list comprehension
Example
list1 = [-11,23,-45,23,-64,-22,-11,24] #list comprehension nos = [num for num in list1 if num < 0] print("Negative numbers in the list: ", nos)
Output
Negative numbers in the list: [-11 -45 -64 -22 -11]
Conclusion
In this article, we learned about the approach to print negative numbers in the input list.
- Related Articles
- Python program to print even numbers in a list
- Python program to print odd numbers in a list
- Python program to count positive and negative numbers in a list
- Golang Program to Print the Sum of all the Positive Numbers and Negative Numbers in a List
- Count positive and negative numbers in a list in Python program
- Python program to print all even numbers in a range
- Python program to print all odd numbers in a range
- Python Program to Print Numbers in an Interval
- Python Program to print unique values from a list
- Python program to print all sublists of a list.
- Lambda expression in Python Program to rearrange positive and negative numbers
- Python program to print duplicates from a list of integers?
- Python program to print all Prime numbers in an Interval
- Python Program to Print Middle most Node of a Linked List
- Python Program to print element with maximum vowels from a List

Advertisements