Intro to Computer Science / Unit 5: Conditionals and Boolean Logic
5.1 Booleans and Comparison Operators
Notes
A Boolean value is either True or False. Comparison operators produce Booleans.
| Operator | Meaning |
|---|---|
== | equal to |
!= | not equal to |
< > | less than, greater than |
<= >= | less than or equal, greater than or equal |
- Use
==to compare. A single=assigns a value; it does not compare. - Example:
7 >= 7isTrue, and"cat" == "Cat"isFalsebecause strings are case sensitive.
Practice
What does
print(10 != 4) display?10 is not equal to 4, so the result is True.
Which operator checks whether two values are equal?
== compares values. = is assignment.
What does
print("Dog" == "dog") display?Uppercase and lowercase letters are different characters, so the strings are not equal.
Ready for more? Take the Unit 5 test.