In Python, these are Boolean values—True and False. Comparison operators produce Booleans: == (equal), != (not equal), and >, <, >=, <= for ordering. Remember: the result of a comparison is not a number, it’s True or False. Let’s print some comparisons to see the outcomes before we use them in conditionals.
Example A: Numeric Comparisons
print(10 > 3) # True
print(2 == 4) # False
print(7 != 7) # False
print(5 <= 5) # True
Each line yields a Boolean. You can print() comparisons directly or store them in a variable like is_big = (10 > 3).
Example B: String Comparisons (Case-Sensitive)
print("apple" == "Apple") # False (different cases)
print("A" < "a") # True (uppercase < lowercase in ASCII)
print("cat" < "dog") # True (lexicographic order)
# normalize case before compare:
print("apple".lower() == "Apple".lower()) # True
String comparison is performed based on lexicographic order and character encoding, and the case of letters will affect the result; in practical use, it is common to apply .lower() or .upper() to unify the case before comparison.
Example C: Store Boolean Result
score = 78
is_pass = (score >= 60)
print("Pass? ", is_pass) # Pass? True
Common Pitfalls:
= (assignment) and == (comparison).input() returns a string; convert before numeric comparisons..lower() if needed.Now that we can evaluate expressions to True or False, we’ll move to Lesson 3 and make the program act differently based on those results using if / elif / else.