Python Program to Check if a Number is Odd or Even Last Updated : 27 Nov, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report Try it on GfG Practice Even Numbers are exactly divisible by 2 and Odd Numbers are not exactly divisible by 2. We can use modulo operator (%) to check if the number is even or odd. For even numbers, the remainder when divided by 2 is 0, and for odd numbers, the remainder is 1.In this article, we will learn how to check if given number is Even or Odd using Python. Python x = 24 # Check the remainder dividing x by 2 is 0 if x % 2 == 0: print("Even") else: print("Odd") # Checking another number x = 7 if x % 2 == 0: print("Even") else: print("Odd") OutputEven Odd Use lambda with map [Memory Efficient]We have defined same as above logic with lambda and applied this to every list element using map Python a = [1, 2, 3, 4, 5] res = map(lambda num: str(num) + " Even" if num % 2 == 0 else str(num) + " Odd", a) print("\n".join(res)) Output1 Odd 2 Even 3 Odd 4 Even 5 Odd Note: Using map is more memory-efficient because it creates an iterator instead of creating an entire list in memory.Using Bitwise And(&) OperatorAnother way to check whether a number is even or odd is by using the bitwise AND operator (&). In binary representation. Bitwise AND (&) operator gives 1 only for (1&1) otherwise it gives 0. So, knowing this we are going to evaluate the bitwise AND of a number with 1 and if the result is 1 number is odd, and if it is 0 number is even. Python x = 24 # If the least significant bit is 0 # the number is even otherwise, it's odd if x & 1 == 0: print("Even") else: print("Odd") # Checking another number x = 7 if x & 1 == 0: print("Even") else: print("Odd") OutputEven Odd Comment More infoAdvertise with us Next Article Python Program to Check if a Number is Odd or Even R rohit2sahu Follow Improve Article Tags : Technical Scripter Python Python Programs Technical Scripter 2020 Number Divisibility python +2 More Practice Tags : pythonpython Similar Reads Python Program to Check Number is a Power of Two we will discuss how to write a Python program to determine whether a given number is a power of two. A number is said to be a power of two if it can be expressed in the form of 2n, where n is a non-negative integer.Examples: Pythondef is_power_of_two(n): if n <= 0: return False return (n & (n 4 min read Python Program to Count Even and Odd Numbers in a List In Python working with lists is a common task and one of the frequent operations is counting how many even and odd numbers are present in a given list. The collections.Counter method is the most efficient for large datasets, followed by the filter() and lambda approach for clean and compact code. Us 4 min read Python program to print even numbers in a list Getting even numbers from a list in Python allows you to filter out all numbers that are divisible by 2. For example, given the list a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], you might want to extract the even numbers [2, 4, 6, 8, 10]. There are various efficient methods to extract even numbers from a li 3 min read Python program to count Even and Odd numbers in a Dictionary Given a python dictionary, the task is to count even and odd numbers present in the dictionary. Examples: Input : {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e' : 5}Output : Even = 2, odd = 3Input : {'x': 4, 'y':9, 'z':16}Output : Even = 2, odd = 1 Approach using values() Function: Traverse the dictionary and 3 min read Python Program to Print Largest Even and Largest Odd Number in a List Auxiliary Given a list. The task is to print the largest even and largest odd number in a list. Examples: Input: 1 3 5 8 6 10 Output: Largest even number is 10 Largest odd number is 5 Input: 123 234 236 694 809 Output: Largest odd number is 809 Largest even number is 694 The first approach uses two 7 min read Like