Python Comparison Operators
Comparison Operators
Comparison operators are used to compare two values:
Operator | Name | Example | Try it |
---|---|---|---|
== | Equal | x == y | Try it » |
!= | Not equal | x != y | Try it » |
> | Greater than | x > y | Try it » |
< | Less than | x < y | Try it » |
>= | Greater than or equal to | x >= y | Try it » |
<= | Less than or equal to | x <= y | Try it » |
Examples
Comparison operators return True
or False
based on the comparison:
Example
x = 5
y = 3
print(x == y)
print(x != y)
print(x > y)
print(x < y)
print(x >= y)
print(x <= y)
Try it Yourself »
Chaining Comparison Operators
Python allows you to chain comparison operators: