Comparison Operators
Before conditionals we must first learn to use comparison operators. Like logical operators, comparison operators return Booleans. Comparison operators compare two operands. One on the left and one on the right. If the comaprison is true, the operation returns true. If the comaparison is false, the operation returns false. There are a number of comparison operators available to use in Python. The following table describes them:
Name | Operator | Description | Example |
---|---|---|---|
Equality | == | Check if operands are equal | 2 == 2 |
Inequality | != | Check if operands are not equal | 4 != 2 |
Less Than | < | Check if left operand is less than right operand | 2 < 4 |
Less Than or Equal | <= | Check if left operand is less than or equal to right operand | 6 <= 7 |
Greater Than | > | Check if left operand is greater than right operand | 8 > 4 |
Greater Than or Equal | >= | Check if left operand is greater than or equla to right operand | 7 >= 3 |