Program to find the even numbers from a given list

In this python function program, we will find the even numbers from a given list.

Even number:
Even numbers are those numbers that can be divided into two equal parts.

What is Function?
It is a block of code that executes when it is called.
To create a function use def keyword.

Steps to solve the program
  1. Create a function even.
  2. Use the def keyword to define the function.
  3. Pass a parameter i.e. list to the function.
  4. Create an empty list.
  5. Use a for loop to iterate over the numbers in the list.
  6. Use an if-else statement to check whether the number is a even number.
  7. If yes then add it to the empty list.
  8. Print the output.
  9. Create a list and pass that list to the function while calling the function.
				
					def even(list1):
    even_list = []
    for val in list1:
        if val%2 == 0:
            even_list.append(val)
    print(even_list)
            
l = [1, 2, 3, 4, 5, 6, 7, 8, 9]
even(l)
				
			

Output :

				
					[2, 4, 6, 8]
				
			

Related Articles

take a number as a parameter and checks whether the number is prime or not.

create and print a list where the values are squares of numbers between 1 to 10.

Leave a Comment