How to check the parity of a number in Python

The parity of a number can be even or odd. For example, 8 is even and 9 is odd.

Solution for How to check the parity of a number in Python : You can use the modulo operator to check the parity of a number The modulo operator % returns the remainder from dividing by a number. Use the format a_number % 2 to check if a_number is divisible by 2.

is_even = 9 % 2 == 0


how-to-check-the-parity-of-a-number-in-python