The Light Switches of Code
A Boolean (or bool) is the simplest data type in Python. Think of it like a light switch. It can only be one of two things: True (On) or False (Off).
We use Booleans to make decisions in our code, like checking if a user is logged in, or if a game is over.
1. Creating Booleans
# Think of this like answering a Yes/No question
is_raining = True
has_ticket = False
game_over = False
2. The Golden Rule of Booleans
In Python, Booleans are incredibly strict about spelling. You must use a capital T for True and a capital F for False.
# CORRECT
is_active = True
# ERROR! Python will crash.
is_active = true
is_active = TRUE
You also don't use quotation marks for Booleans. If you write "True", Python will think it's just a normal String (text), not a real Boolean switch!
What's Next?
You now know the 3 foundational building blocks of Python: Strings (Words), Numbers (Math), and Booleans (Yes/No). Let's practice using them in the exercises page next!