โ† Back to Python Course
๐Ÿค” Making Decisionsยท15 minยทBeginner
โœ…

Booleans

True, False, and nothing else

Meet the simplest data type in Python: True or False. Just two options, but incredibly powerful!

๐Ÿ“–

What we are learning

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!

๐ŸŒŸ

Why it matters

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:

  • โœ“Games track whether a level is completed (True/False)
  • โœ“Apps check if you are online or offline
  • โœ“Security systems check if a door is locked or unlocked
๐ŸŽฏ

By the end, you can:

  • 1.Create boolean variables (True and False)
  • 2.Use booleans in if statements
  • 3.Combine booleans with and, or, not
๐Ÿ”ค

New words

booleanTrueFalseandornot
๐Ÿ
Name three things in your room that are either on or off, true or false. Can you think of something that is NOT a boolean?
๐Ÿค“

Fun Fact!

Booleans are named after George Boole, a mathematician who invented a whole system of logic using just True and False!

โœ… True or 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.

โœจ Creating Booleans

๐ŸCreate boolean variables
main.py
โ— Output
True and False must start with capital letters!

๐Ÿ”— Combining Booleans

You can combine booleans with three special words:

๐Ÿ”—
and
Both must be True
โšก
or
At least one True
๐Ÿšซ
not
Flips True/False
๐ŸCombine booleans with and, or, not
main.py
โ— Output
Click โ–ถ Run to see the output!

๐Ÿงช Truth Table

Here is how and, or, and not work:

ABA and BA or Bnot A
TrueTrueTrueTrueFalse
TrueFalseFalseTrueFalse
FalseTrueFalseTrueTrue
FalseFalseFalseFalseTrue
๐Ÿ
Try this: create a boolean called 'likes_pizza' and another called 'likes_broccoli'. Use 'and' to check if someone likes both!
๐Ÿง 

Quick Quiz!

+10 XP

What is the result of True and False?

๐Ÿ
Finished the lesson? Click the button to mark it complete and earn XP!