Answers for "get a list of even numbers in python"

-3

get a list of even numbers in python

num_range = 10
even_numbers = [num for num in range(num_range) if num % 2 == 0]
# returns: [0, 2, 4, 6, 8]
# to include 10 in the output do
even_numbers = [num for num in range(num_range + 1) if num % 2 == 0]
Posted by: Guest on February-26-2021

Python Answers by Framework

Browse Popular Code Answers by Language