True, False, and nothing else
Meet the simplest data type in Python: True or False. Just two options, but incredibly powerful!
A boolean is a value that can only be True or False. That is it โ just two options! But booleans are the foundation of all decision-making in programming. Every if statement checks a boolean.
๐ก Think of it like this:
Think of a boolean like a light switch. It is either ON (True) or OFF (False). There is no "kind of on" or "maybe off." Simple, but you use light switches every day!
Booleans are the language computers use to make decisions. Is the game over? True or False. Is the user logged in? True or False. Every choice a computer makes comes down to a boolean.
Where you see this in real life:
Booleans are named after George Boole, a mathematician who invented a whole system of logic using just True and False!
A boolean is a value that can only be Trueor False. That is it โ just two options! But booleans are the foundation of all decision-making in programming.
Important: In Python, True and False start with capital letters!true(lowercase) will NOT work.
True and False must start with capital letters!You can combine booleans with three special words:
Click โถ Run to see the output!Here is how and, or, and not work:
| A | B | A and B | A or B | not A |
|---|---|---|---|---|
| True | True | True | True | False |
| True | False | False | True | False |
| False | True | False | True | True |
| False | False | False | False | True |
What is the result of True and False?