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.
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.
Run Code Copy
a = 8
b = 8
if a == b :
print('The two numbers are equal.')
print('The two numbers are not equal.')
The two numbers are equal.
In this tutorial of Python Examples, we learned how to check if two given numbers are equal using equal-to operator.