Python program to print even numbers in a list
In this article, we will learn to find the even number from the given list and print it in the list format.
How to check whether the given is even or not?
If a number is completely divisible by 2, then the given number is even.
We find the even number in a list using 1 method:
- Using loop
- First, we initialize a list.
- Then we create a new list to store the evens number (named result).
- After, that we will run the loop to get all elements of the list one by one.
- Then, we will check each element, whether it's completely divisible by the 2 or not.
- We will check using the modulus(%) operator.
- If the element is completely divisible by 2, then append to the new list result.
- And after all, print the result list.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
# list list = [1,2,3,4,5,6,7,8] # result list result =  # iterate all element of list for ele in list: # check for even if ele%2==0: result.append(ele) # append the even number in result list # print the result print(result)
[2, 4, 6, 8]