Skip to main content

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!


Quick Summary

  • Boolean Definition: A binary logical data type that holds only one of two states: True or False.
  • Capitalization Rule: Must always be capitalized (True and False, never true or false).
  • No Quotes: Do not enclose booleans in quotes; "True" is a str, whereas True is a bool.
  • Truthiness (bool()): Empty values (like 0, "", [], None) evaluate to False; non-empty values evaluate to True.

What's Next?

You now know the 4 foundational building blocks of Python: Strings (Words), Integers & Floats (Math), and Booleans (Yes/No). Let's learn how to display information and take inputs from users in Module 3: Input & Output!