Python Program – Check if two numbers are equal

Check if given two numbers are equal

To check if two given numbers are equal in Python, use comparison equal to operator. Pass the two numbers as operands to the equal-to operator. If the two numbers are equal, the operator returns True, else it returns False.

Program

In the following program, we take two numbers in a and b. We check if these two numbers are equal using equal-to operator.

Since the equal-to operator returns a boolean value, we will use the expression a == b as a condition for if-else statement.

Python Program

a = 8
b = 8

if a == b :
    print('The two numbers are equal.')
else :
    print('The two numbers are not equal.')
Run Code Copy

Output

The two numbers are equal.

Summary

In this tutorial of Python Examples, we learned how to check if two given numbers are equal using equal-to operator.

Related Tutorials

Code copied to clipboard successfully 👍