Comparison Operators

Operators

Comparison Operators

🙋 Need help? Ask an expert now!

Comparing Variables

Comparison operators are used to compare two values:

Operator Description Example
== If the values of two operands are equal, then the condition becomes true (2 == 3) returns False
!= If values of two operands are not equal, then condition becomes true (2 != 3) returns True
<> If values of two operands are not equal, then condition becomes true (2 <> 3) is True. This is similar to != operator.
> If the value of left operand is greater than the value of right operand, then condition becomes true (2 > 3) returns False
< If the value of left operand is less than the value of right operand, then condition becomes true (2 < 3) returns True
>= If the value of left operand is greater than or equal to the value of right operand, then condition becomes true (2 >= 3) returns False
<= If the value of left operand is less than or equal to the value of right operand, then condition becomes true (2 <= 3) returns True
                        
# is 2 less than 3? print('Is 2 < 3? ', 2 < 3 ) # is 2 greater than 3? print('Is 2 > 3? ', 2 > 3 ) # is 2 equal to 3? print('Is 2 = 3? ', 2 == 3 ) # is 2 not equal to 3? print('Is 2 != 3? ', 2 != 3 )
Edit Me on GitHub!