Python Tutorials · Python Operators

Comparison Operators

Learn all about Comparison Operators in this comprehensive tutorial.

5 min read beginner
  • Comparison operators are used to compare two values:
  • Comparison operators return True or False based on the comparison:
  • Python allows you to chain comparison operators:

Comparison Operators

Comparison operators are used to compare two values:

OperatorNameExampleTry it
==Equalx == yTry it »
!=Not equalx != yTry it »
>Greater thanx > yTry it »
<Less thanx < yTry it »
>=Greater than or equal tox >= yTry it »
<=Less than or equal tox <= yTry it »

Examples

Comparison operators return True or False based on the comparison:

python

Chaining Comparison Operators

Python allows you to chain comparison operators:

python

Module quiz

2 questions
1

Which of the following is true about Comparison Operators?

2

What is the most common pitfall when working with Comparison Operators?

Answer all questions to submit.