Python lesson
Comparisons
> is greater than, < is less than, and == asks 'is it equal?'. Two equals signs compare. One equals sign stores a value.
Try this lesson free →Example
A comparison checks something and gives back True or False:
revenue = 70
print(revenue > 50)
print(revenue < 50)
print(revenue == 70)
store = "Lagos"
print(store == "Abuja")True
False
True
FalseKey points
> < >= <=Greater than, less than, and their 'or equal to' versions.
==Is it equal? Two equals signs. One = stores a value instead.
!=Is it different? store != "Lagos" is True for Abuja.
Every comparison gives True or False. Next, you'll use them to make decisions.
Practice
1. Build a line that shows whether revenue is greater than 100.
print(revenue > 100)2. Build a line that shows whether store equals Lagos.
print(store == "Lagos")3. Print whether qty is less than 3.
qty = 4
print(qty < 3)4. Print whether product equals Earbuds.
product = "Charger"
print(product == "Earbuds")5. Print whether revenue is at least 70 (70 or more).
revenue = 70
print(revenue >= 70)Learn it by doing. This lesson is a short hands-on level on Bampaa: see it work, then build and write it yourself, with instant feedback.
Try this lesson free →