Skip to main content
Practice

Generating Boolean Values with Comparison Operators

comparison operators generate Boolean values by comparing different values or variables.


What are the comparison operators?

In Python, you can use the following comparison operators:

  • Equality (==): Compares if the values on both sides of the operator are equal.

  • Inequality (!=): Compares if the values on both sides of the operator are different.

  • Relational Comparison (>, <, >=, <=): Compares the size of the values on both sides of the operator.


Example of using comparison operators
x = 5
y = 3

# Equality
print(x == y) # False

# Inequality
print(x != y) # True

# Relational Comparison
print(x > y) # True

print(x < y) # False

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.