Print even numbers in a list - Python
Last Updated :
11 Jul, 2025
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 list. Let's explore different methods to do this efficiently.
Using List comprehension
List comprehensions is an efficient way to filter elements from a list. They are generally considered more Pythonic and faster than traditional loops.
Python
a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
res = [val for val in a if val % 2 == 0]
print(res)
Explanation: [val for val in a if val % 2 == 0] iterates through the list a and selects only the even numbers.
Using filter()
filter() function provides a functional programming approach to filter elements from a list. It can be a bit less intuitive compared to list comprehensions, but it is still very useful.
Python
a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
res = list(filter(lambda val: val % 2 == 0, a))
print(res)
Explanation: filter() function takes lambda function that tests each element in the list. lambda val: val % 2 == 0 returns True for even numbers, which are then included in the final list. We convert the result to a list using list().
Using loop
Using a traditional for loop is the most straightforward method, but it is generally less efficient and more verbose compared to other methods.
Python
a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
for val in a:
if val % 2 == 0:
print(val, end=" ")
Explanation: For loop iterates through each element in the list a. If the element is divisible by 2 (even number), it is printed.
Using Bitwise AND operator
This is a low-level, bitwise approach to check if a number is even. It works by performing a bitwise AND operation with 1, which will return 0 for even numbers and 1 for odd numbers.
Python
a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
res = [val for val in a if val & 1 == 0]
print(res)
Explanation: expression val & 1 == 0 uses the bitwise AND operator to check if the least significant bit of a number is 0. Even numbers have their least significant bit as 0, so the condition evaluates to True for even numbers.
Related Articles
Similar Reads
Print odd numbers in a List - Python 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 LoopThe most basic way to print odd nu
2 min read
Print odd numbers in a List - Python 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 LoopThe most basic way to print odd nu
2 min read
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
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
Print lists in Python Printing a list in Python is a common task when we need to visualize the items in the list. There are several methods to achieve this and each is suitable for different situations. In this article we explore these methods.The simplest way of printing a list is directly with the print() function:Pyth
3 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