You've stored numbers, strings, and computed sums. Today's a different shape of value: an answer to a yes-or-no question. What's 7 > 5 — true or false?
True. Seven is bigger than five.
Python agrees, and gives back a value with that name: True. There's also False. Together those two are the boolean type. Comparison operators always return one or the other:
print(7 > 5) # True
print(2 > 5) # False
print(5 == 5) # True
print(5 == 6) # FalseWhy == for equality? You used single = for assignment.
That's exactly why. Single = was already taken — it means set this variable. To compare two values for equality, Python uses double ==. They look similar; they do entirely different things. Mixing them up is the most common Python typo.
What other comparisons are there?
The full set is < > <= >= == !=. The last is not equal — 5 != 6 is True. They all return a boolean.
And these work on strings too?
They do. == and != work as you'd expect: "hello" == "hello" is True. The ordering operators < > work alphabetically (more precisely: by Unicode code point), so "a" < "b" is True and "banana" < "cherry" is True. Useful when sorting; rarely needed in early lessons.
Can I store a boolean in a variable?
Just like any other value. is_ready = 7 > 5 stores True in is_ready. The variable now holds a boolean and you can use it later — print it, compare it, pass it around.
So booleans are the answer Python gives when I ask it a question. And tomorrow I'll be using them to make decisions in code.
Exactly. Booleans are the bridge from values to behaviour — when an if statement asks "do this if true," it's a boolean it's checking.
True and FalseA boolean has exactly two possible values:
yes = True
no = FalseNote the capitalisation: True and False with capital first letters. true (lowercase) is a NameError in Python. The two values are written like Python keywords.
Every comparison returns a boolean:
| Operator | Meaning | Example | Result |
|---|---|---|---|
== | equal to | 5 == 5 | True |
!= | not equal to | 5 != 6 | True |
< | less than | 2 < 5 | True |
> | greater than | 5 > 2 | True |
<= | less than or equal | 5 <= 5 | True |
>= | greater than or equal | 5 >= 6 | False |
= is not ==The single most common Python typo:
| Operator | Meaning | Example |
|---|---|---|
= | assignment (set the variable) | x = 5 |
== | equality test (does it equal?) | x == 5 |
If you find your if statement is mysteriously assigning instead of comparing, check whether you wrote = where you meant ==. (Python 3 actually catches this in some contexts — if x = 5: is a syntax error — but in others, like inside an expression, it can quietly do the wrong thing.)
== and != work as expected:
print("hello" == "hello") # True
print("Hello" == "hello") # False (case matters)< and > compare strings character-by-character using Unicode code points. For ASCII letters this matches alphabetical order:
print("apple" < "banana") # True
print("a" < "b") # TrueUppercase letters sort before lowercase: "Z" < "a" is True. Surprising at first — worth knowing if you compare mixed-case strings.
You can store the result of a comparison in a variable, just like any other value:
is_adult = age >= 18
print(is_adult) # True or False, depending on ageWhen you print a boolean, you see the literal word True or False. (Capitalised, as the values are written.)
By themselves they're not very interesting. Their real use is to drive decisions — if statements (which you'll meet in week 2) ask Python "is this boolean true?" and run different code depending on the answer. Booleans are the steering wheel of every program that does more than mechanical arithmetic.
You've stored numbers, strings, and computed sums. Today's a different shape of value: an answer to a yes-or-no question. What's 7 > 5 — true or false?
True. Seven is bigger than five.
Python agrees, and gives back a value with that name: True. There's also False. Together those two are the boolean type. Comparison operators always return one or the other:
print(7 > 5) # True
print(2 > 5) # False
print(5 == 5) # True
print(5 == 6) # FalseWhy == for equality? You used single = for assignment.
That's exactly why. Single = was already taken — it means set this variable. To compare two values for equality, Python uses double ==. They look similar; they do entirely different things. Mixing them up is the most common Python typo.
What other comparisons are there?
The full set is < > <= >= == !=. The last is not equal — 5 != 6 is True. They all return a boolean.
And these work on strings too?
They do. == and != work as you'd expect: "hello" == "hello" is True. The ordering operators < > work alphabetically (more precisely: by Unicode code point), so "a" < "b" is True and "banana" < "cherry" is True. Useful when sorting; rarely needed in early lessons.
Can I store a boolean in a variable?
Just like any other value. is_ready = 7 > 5 stores True in is_ready. The variable now holds a boolean and you can use it later — print it, compare it, pass it around.
So booleans are the answer Python gives when I ask it a question. And tomorrow I'll be using them to make decisions in code.
Exactly. Booleans are the bridge from values to behaviour — when an if statement asks "do this if true," it's a boolean it's checking.
True and FalseA boolean has exactly two possible values:
yes = True
no = FalseNote the capitalisation: True and False with capital first letters. true (lowercase) is a NameError in Python. The two values are written like Python keywords.
Every comparison returns a boolean:
| Operator | Meaning | Example | Result |
|---|---|---|---|
== | equal to | 5 == 5 | True |
!= | not equal to | 5 != 6 | True |
< | less than | 2 < 5 | True |
> | greater than | 5 > 2 | True |
<= | less than or equal | 5 <= 5 | True |
>= | greater than or equal | 5 >= 6 | False |
= is not ==The single most common Python typo:
| Operator | Meaning | Example |
|---|---|---|
= | assignment (set the variable) | x = 5 |
== | equality test (does it equal?) | x == 5 |
If you find your if statement is mysteriously assigning instead of comparing, check whether you wrote = where you meant ==. (Python 3 actually catches this in some contexts — if x = 5: is a syntax error — but in others, like inside an expression, it can quietly do the wrong thing.)
== and != work as expected:
print("hello" == "hello") # True
print("Hello" == "hello") # False (case matters)< and > compare strings character-by-character using Unicode code points. For ASCII letters this matches alphabetical order:
print("apple" < "banana") # True
print("a" < "b") # TrueUppercase letters sort before lowercase: "Z" < "a" is True. Surprising at first — worth knowing if you compare mixed-case strings.
You can store the result of a comparison in a variable, just like any other value:
is_adult = age >= 18
print(is_adult) # True or False, depending on ageWhen you print a boolean, you see the literal word True or False. (Capitalised, as the values are written.)
By themselves they're not very interesting. Their real use is to drive decisions — if statements (which you'll meet in week 2) ask Python "is this boolean true?" and run different code depending on the answer. Booleans are the steering wheel of every program that does more than mechanical arithmetic.
Create a free account to get started. Paid plans unlock all tracks.