Booleans and Comparisons
15 min In ProgressLearning Objectives
- Understand True and False
- Use comparison operators
- Combine conditions with and, or, not
Boolean Values
Booleans represent truth values: True or False. They are the foundation of decision-making in code.
is_raining = True
has_umbrella = False
print(type(is_raining))
Comparison Operators
Use ==, !=, <, >, <=, >= to compare values and get a boolean result.
x = 10
y = 20
print(x == y) # False
print(x != y) # True
print(x < y) # True
print(x >= 10) # True
Logical Operators
Combine comparisons with and, or, and not.
age = 25
has_id = True
can_vote = age >= 18 and has_id
print(can_vote)
# not flips the value
print(not False)
📝 Exercise: Eligibility Checker
Create variables for age and a boolean has_ticket. Print whether the person can enter (age >= 13 and has_ticket).
code.py
Output