Python Comparison Operators are used to compare values and determine whether one value is greater than, less than, equal to, or not equal to another value.

Comparison Operators

Here are the most commonly used Python Comparison Operators:

  1. == (Equal to): It returns True if the values on either side of the operator are equal. For example, 5 == 5 will return True.
  2. != (Not equal to): It returns True if the values on either side of the operator are not equal. For example, 5 != 4 will return True.
  3. > (Greater than): It returns True if the value on the left side of the operator is greater than the value on the right side. For example, 5 > 4 will return True.
  4. < (Less than): It returns True if the value on the left side of the operator is less than the value on the right side. For example, 4 < 5 will return True.
  5. >= (Greater than or equal to): It returns True if the value on the left side of the operator is greater than or equal to the value on the right side. For example, 5 >= 5 will return True.
  6. <= (Less than or equal to): It returns True if the value on the left side of the operator is less than or equal to the value on the right side. For example, 4 <= 5 will return True.

Example

Python
x = 5
y = 4

# Equal to
print(x == y) #False

# Not equal to
print(x != y) #True

# Greater than
print(x > y) #True

# Less than
print(x < y) #False

# Greater than or equal to
print(x >= y) #True

# Less than or equal to
print(x <= y) #False

You can also use these comparison operators with variables and other data types like strings and lists.

Note: Python Comparison Operators are case-sensitive. For example, "Hello" != "hello" will return True.