Comparison Operators

In this lesson, we'll learn how to perform comparisons in Python using comparison operators.

We'll cover the following

Comparison operators can be used to compare values in mathematical terms.

Operator Purpose Notation
> Greater Than In-fix
< Less Than In-fix
>= Greater Than or Equal To In-fix
<= Less Than or Equal To In-fix
== Equal To In-fix
!= Not Equal To In-fix
is Equal To (Identity) In-fix
is not Not Equal To (Identity) In-fix

Comparisons

The result of a comparison is always a bool.

If the comparison is correct, the value of the bool will be True. Otherwise, its value will be False.

The == and != operators compare the values of both operands. However, the identity operators, is and is not, check whether the two operands are the exact same object.

Let’s look at a few examples:

Get hands-on with 1200+ tech skills courses.