A Boolean is a data type that can be either True or False. It's often the result of comparisons or logic.
Compare two values using these operators:
| Operator | Name | Example |
|---|---|---|
== | Equal to | 5 == 5 |
!= | Not equal | 5 != 3 |
> | Greater than | 5 > 3 |
< | Less than | 2 < 1 |
>= | Greater or equal | 5 >= 5 |
<= | Less or equal | 4 <= 3 |
Logical operators let you combine multiple Boolean expressions. Try the examples below and predict whether they will evaluate to True or False. Then run the code to check your answers.
and – True only if both conditions are Trueor – True if at least one condition is Truenot – Reverses the Boolean valuePredict the result of each line, then run the code to check if you're right:
Some values evaluate to False:
0, "", [], None → FalsyThese are helpful in comparisons:
🔹 What will each of these print?
Booleans are used in real-world logic checks, conditionals, and flows:
Ask the AI if you need help understanding or want to dive deeper in any topic