~/learn/Python · Fundamentals
Comparisons, booleans and missing values
Ask true-or-false questions and combine conditions with and, or and not.
why this matters
Filtering data and choosing actions both start with a clear true-or-false question.
A boolean is a value with two possibilities: True or False, written with capital letters and no quotes. Comparisons produce booleans. == means equal to, != means not equal to, > and < mean greater than and less than. >= and <= include equality.
Try it: Change score to 80. Which comparisons change?
Assign versus compare
score = 70 → store 70 under the name score score == 70 → ask whether score equals 70 'False' → text, not the boolean False
and requires both conditions to be true. or requires at least one to be true. not reverses a boolean. Use parentheses to make grouped conditions readable rather than relying on remembering operator precedence.
Try it: Set has_ticket to False. Predict all three results.
None represents the absence of a value, not zero and not the text "None". Use is None to check specifically for a missing value. This matters because a score of 0 can be a valid result, while None means a score has not been recorded.
Try it: Start recorded_score at 50. Is it missing? Is it zero?
Truthiness, in plain English
A condition can also treat a value as true or false. Zero, empty text (""), empty collections and None are false-like; most other values are true-like. bool("False") is True because that text is not empty. Prefer explicit comparisons while learning.
key takeaways
- True and False are booleans, not quoted text.
- == compares while = assigns.
- and needs both conditions; or needs at least one; not reverses a boolean.
- None means a missing value; zero can be a valid value.
check your understanding
age = 20 has_ticket = False What is age >= 18 and has_ticket?
free practice
Build confidence with a question you can solve without Pro.