bugl
bugl
HomeLearnPatternsSearch
HomeLearnPatternsSearch

Loading lesson path

Learn/Python/Foundations Practice
Python•Foundations Practice

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 » >

Formula

Greater than x > y

Try it » <

Formula

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)

Chaining Comparison Operators

Python allows you to chain comparison operators:

Example x = 5 print(1 < x < 10)
print(1 < x and x < 10)

Previous

Python Assignment Operators

Next

Python Logical Operators