Lecture
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
Previous lessonBoolean Data Type for Determining True or FalseNext lessonUsage of and, or, not Logical Operators
Lessons in this chapter · Boolean Data Type and Logical Operators
- 1. Boolean Data Type for Determining True or False
- 2. Generating Boolean Values with Comparison Operators
- 3. Usage of and, or, not Logical Operators
- 4. Multiple-choice quiz
- 5. Checking if Two Objects Are Identical with the is Operator
- 6. The not Operator Returning the Opposite
- 7. Combining Boolean Values with and, or Operators
- 8. Coding Quiz - Compare Values
- 9. Multiple-choice quiz
- 10. Fill-in-the-blank quiz
Quiz
0 / 1
Which of the following cases is True?
5 == 3
5 < 3
5 != 3
5 <= 3
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help