def filter_even(number_list):
result_list = []
for number in number_list:
if number % 2 == 0:
result_list.append(number)
return result_list
So this is a function to return all even numbers in a list. All it’s doing is that for every value in the list, it checks whether or not it’s divisible by two.
This % is the Modulus operator that returns the remainder of the division. number % 2 will return 0 if a number is completely divisible by 2.
If the condition is satisfied, it will append the current value to our resultant list.