Just like in any other OOP languages, Python uses comparison operators to compare values. These are often called Boolean operators, because the word Boolean indicates that the result of using the comparison operator is a Boolean value: true or false. What follows is a list of the Boolean values that can be used in Python when evaluating expressions, writing functions, and comparing values. Take a look:

  • == indicates that you're trying to discern if two values are equal to each other -- be sure to use two equals signs, not one!
  • != indicates that you're trying to discern if two values are not equal to each other. So if you had an expression like:
7 != 10

your answer would be the Boolean value: true.

  • < this one indicates that you're comparing two values to see if the first value is less than the second, like this:
7 < 10

So here, your answer would also be your Boolean value: true.

  • this operator indicates that you're comparing two values to see if the first one is greater than the second. So in the same example as above with the greater than sign replacing the lefthand side, you'd get a Boolean result of false, because 7 is not greater than 10.
  • <= this one indicates that you're comparing two values to see if the first is less than or equal to the second. So if you have the following expression:
10 <= 10

your answer would be the Boolean value true, because 10 is equal to 10 (it's not less than ten, but               we're checking for less than OR equal to)

  • >= you can probably guess what this operator is, but just in case you can't it's used to indicate that you're comparing two values to see if the second is greater than or equal to the first. So if you switched the signs in the example above from less than or equal to to greater than or equal to, you'd still get the same true value because 10 is still equal to 10.

About The Author