Equality Operator
We learned how to create and store values, but how do we compare them?
To compare if two numbers are the same, we use the equality operator == .
When comparing, there are only two results: True or False . When we compare the same numbers with the equality operator, the result is True . When we compare the different numbers with the equality operator, the result is False .
Example:
Let’s use 9 to 10 comparison.
print (9==10)
Output:
False
Example:
print(10==10)
Output:
True
Inequality Operator
To check if a number isn’t equal to another number, we use the inequality operator != .
We can store the result of a comparison with the inequality operator in a variable. Variables can store the result of equality comparisons too, such as
result = 1==2
print (result)
Output:
False
We can compare values with variables and variables with other variables with == .
Example:
one=1
two=2
print(one==two)
print(one!=two)
Output:
False
True