Unit 04 · lesson
True, False, and Comparisons
Core path: 30 minutes
How does Python turn data into a decision?
Week 3 gave the program values. Week 4 asks questions about those values.
A decision starts with an expression that can be evaluated as True or False.
A Boolean is a value
robot_online = True
game_over = False
True and False are Boolean values. They are not the strings "True" and "False".
Most of the time, you will not type Boolean values directly. Python will produce them by evaluating a comparison.
battery = 18
print(battery <= 20)
Python does not read that as English. It evaluates the left value, the operator, and the right value and produces one Boolean result.
battery → 18
18 <= 20
↓
True
That Boolean can later control a branch.
Translate the operator into a question
Use comparisons as questions:
| Expression | Read it as |
|---|---|
score == 100 | Is score equal to 100? |
score != 100 | Is score not equal to 100? |
age > 15 | Is age greater than 15? |
age < 15 | Is age less than 15? |
score >= 70 | Is score at least 70? |
battery <= 20 | Is battery 20 or lower? |
This is better than memorizing symbols in isolation because requirements usually arrive in words first.
Words such as at least, no more than, below, and greater than hide exact boundary rules.
Assignment and comparison are different operations
score = 100
changes program state by assigning a value.
score == 100
evaluates a question and produces True or False.
One equals sign and two equals signs are not alternate spellings.
Try reading them aloud:
score = 100 → assign 100 to score
score == 100 → is score equal to 100?
That difference becomes much easier to remember when you attach a job to each operator.
Boundary language matters
Suppose the requirement says:
A battery is low at 20 percent or below.
Then:
battery <= 20
matches the requirement.
This does not:
battery < 20
The second expression excludes exactly 20.
Test the boundary pair:
19 → True
20 → True
21 → False
Use the runtime to make that one-character policy change visible:
Run the code to see output.
Use the output as boundary evidence. Change <= to < and identify the exact input whose Boolean result changes. Then compare the case-sensitive string results.
One character in the operator can change the policy of the program.
Comparisons work with strings too
username = "neo"
print(username == "neo") # True
print(username == "Neo") # False
Python strings are case-sensitive by default. Those values contain different characters.
If your requirement says capitalization should not matter, you need to normalize or otherwise define that behavior deliberately. Python will not infer the policy.
Predict the Boolean evidence
score = 75
print(score > 50)
print(score == 75)
print(score != 75)
print(score <= 100)
Before running, trace one value through four questions:
75 > 50 → True
75 == 75 → True
75 != 75 → False
75 <= 100 → True
Then run it.
If one prediction was wrong, identify whether you misunderstood the value, the operator, or the boundary.
A Boolean expression is evidence, not action
This line:
score >= 70
can evaluate to True, but by itself it does not print anything, grant access, or move a robot.
It produces information.
Lesson 2 uses that information to choose an execution path.
That separation is important:
comparison → Boolean result
branch → action chosen because of that result
Boolean Detective
Given:
age = 15
score = 82
username = "nova"
is_admin = False
Predict:
age >= 13
score > 90
username == "nova"
username == "Nova"
is_admin == True
score != 82
For each expression, record:
left value:
operator:
right value:
result:
For is_admin == True, ask whether the comparison is even necessary. A Boolean variable can often be used directly later:
if is_admin:
...
We will use that in Lesson 3.
Vocabulary lab
Flip the idea, not just the card
Explain the term before you reveal the back. Then compare your explanation with the definition, example, and warning.
Read all terms without animation
- Boolean
- A logical value that is either True or False. Example: game_over = False Do not confuse it with: The string 'False', which is text.
- Boolean Expression
- An expression evaluated to produce True or False. Example: battery <= 20 Do not confuse it with: An assignment such as battery = 20.
- Comparison Operator
- An operator that compares values and produces a Boolean result. Example: ==, !=, <, >, <=, and >=. Do not confuse it with: The assignment operator =.
- Boundary Value
- A value at or immediately beside the point where a rule changes outcome. Example: 20 and 21 for the rule battery <= 20. Do not confuse it with: A random test value far away from the threshold.
- Case Sensitivity
- Treating uppercase and lowercase characters as different values. Example: 'neo' == 'Neo' is False. Do not confuse it with: A comparison that deliberately normalizes capitalization first.