Print all even numbers in a range - Python Last Updated : 26 Apr, 2025 Summarize Suggest changes Share Like Article Like Report Our task is to print all even numbers within a given range. The simplest way to achieve this is by using a loop to iterate through the range and check each number for evenness. Let's explore some methods to do so.Using LoopWe can use a for loop with if conditional to check if a number is even. Python s = 1 e = 10 for i in range(s, e + 1): if i % 2 == 0: print(i) Output2 4 6 8 10 Explanation:We loop through all the numbers in the given range (s to e).The condition i % 2 == 0 checks if the number is even (i.e., divisible by 2).If the condition is True than print the number.Using List ComprehensionList comprehension provides a concise way to filter even numbers and print them directly. Python s = 1 e = 10 res = [i for i in range(s, e + 1) if i % 2 == 0] print(res) Output[2, 4, 6, 8, 10] Explanation:This list comprehension generates a list of numbers from s to e where i % 2 == 0 (i.e., the number is even).The result is a list of even numbers which is then printed.Using range() with StepThe built-in range() function can also be used efficiently to print even numbers by setting a step value of 2. This avoids the need for an extra if condition. Python s = 1 e = 10 for i in range(2, e + 1, 2): print(i) Output2 4 6 8 10 Explanation:The range(2, e+ 1, 2) generates numbers starting from 2 and increments by 2, this producing only even numbers.No need for an if condition as the range is already defined to only include even numbers.Related Articles:Python For LoopsList Comprehension in PythonPython range() function Advertise with us Next Article How to Round Numbers in Python? S Shivam_k Follow Similar Reads Filter Even Values from a List - Python The task of filtering even values from a list in Python involves selecting elements from the list that are even numbers. For example, given the list a = [1, 2, 3, 4, 5], the goal is to filter out the even values, resulting in a new list like this [2, 4].Using list comprehensionList comprehension pro 2 min read Python program to print even length words in a string The task of printing even-length words from a string in Python involves identifying and extracting words whose lengths are divisible by 2. Given an input string, the goal is to filter out words with an even number of characters and display them. For example , s = "Python is great", the even-length w 3 min read How to Round Numbers in Python? Rounding a number simplifies it while keeping its value as close as possible to the original. Python provides various methods to round numbers, depending on how we want to handle the precision or rounding behavior. In this article, we'll cover the most commonly used techniques for rounding numbers i 4 min read Python Program for Number of elements with odd factors in given range Given a range [n,m], find the number of elements that have odd number of factors in the given range (n and m inclusive). Examples: Input : n = 5, m = 100 Output : 8 The numbers with odd factors are 9, 16, 25, 36, 49, 64, 81 and 100 Input : n = 8, m = 65 Output : 6 Input : n = 10, m = 23500 Output : 2 min read Format a Number Width in Python Formatting numbers to a fixed width is a common requirement in various programming tasks, especially when dealing with data presentation or storage. By understanding these techniques, developers can ensure consistent and visually appealing formatting of numerical data in their Python. Format a Numbe 3 min read SymPy | Permutation.is_even() in Python Permutation.is_even() : is_even() is a sympy Python library function that checks whether the permutation is even. Syntax : sympy.combinatorics.permutations.Permutation.is_even() Return : true - if the permutation is even; otherwise false Code #1 : is_even() Example Python3 1=1 # Python code explaini 1 min read Article Tags : Python python-list Python list-programs Practice Tags : pythonpython-list Like