Skip to content

Python Booleans: True and False

Updated 6 min read Aimerscrew

Is the store open? Did the payment go through? Is the password correct? Programs ask yes-or-no questions all the time, and Python booleans are how they store the answers. A boolean can only ever be one of two values: True or False. In this lesson, you'll learn where booleans come from, which values Python treats as "true" or "false", and how booleans help your code make decisions.

🌍 Real-life example

A light switch is a perfect boolean. It's either on or off; there's no "a bit on". A boolean in Python works the same way: light_on = True or light_on = False, and nothing in between.

What is a boolean in Python?

A boolean (named after the mathematician George Boole) is a value that is either True or False. Its type in Python is called bool.

is_raining = False
has_free_shipping = True

print(is_raining)
print(type(has_free_shipping))
False
<class 'bool'>

Notice that True and False start with a capital letter and have no quotes. They are special keywords, not text.

💡 Tip

Name boolean variables like a yes-or-no question: is_open, has_coupon, can_vote. When you read if is_open: later, it sounds like plain English.

How do comparisons create booleans?

You rarely type True or False by hand. Most booleans come from comparisons, which check how two values relate and answer with a boolean:

print(10 > 3)            # greater than
print(5 == 8)            # equal to
print("cat" != "dog")    # not equal to

battery = 15
print(battery <= 20)     # less than or equal to
True
False
True
True

You can store the result of a comparison in a variable, just like any other value:

hour = 14
is_open = hour >= 9 and hour < 18
print("Store open:", is_open)
Store open: True

The and joins two comparisons: the store is open only if both are true. You'll learn all comparison operators in the Operators chapter.

What are truthy and falsy values in Python?

Python can treat any value as true or false. The built-in bool() function shows you how Python sees it. Values that become False are called falsy; everything else is truthy.

The rule is easy to remember: zero, empty and nothing are False. Everything else is True.

print(bool(0))
print(bool(42))
print(bool(""))
print(bool("hello"))
print(bool([]))
print(bool(None))
False
True
False
True
False
False
Animation: values pass through bool() one by one and drop into a False bin (0, 0.0, empty string, empty list, None, empty dict) or a True bin (42, -3.5, "hi", a space, [0], "False")
Zero, empty and nothing land in the False bin. Everything else, even a single space or the text "False", is True.
Falsy (becomes False)Truthy (becomes True)
0 and 0.0Any other number: 1, -7, 0.01
"" (empty string)Any text: "hi", " ", "0", "False"
[] (empty list)A list with items: [0], [1, 2]
{} (empty dictionary)A dictionary with items: {"a": 1}
NoneMost other values
FalseTrue

⚠️ Be careful

The string "False" is truthy, because it isn't empty. Python doesn't read the word; it only checks whether there's any text at all. The same goes for "0" and " " (a single space).

How are booleans used in if statements?

Booleans really shine in if statements, which run code only when a condition is true. You'll learn if in detail later; here's a quick preview:

is_logged_in = True

if is_logged_in:
    print("Welcome back!")
else:
    print("Please sign in.")
Welcome back!

Thanks to truthy and falsy values, you can check whether something is empty without a comparison:

cart = []

if cart:
    print("Ready to check out")
else:
    print("Your cart is empty")
Your cart is empty

An empty list is falsy, so Python runs the else part.

Combining booleans with and, or and not

Python has three logical operators for combining booleans:

  • and is True only if both sides are True.
  • or is True if at least one side is True.
  • not flips a boolean: True becomes False and False becomes True.
is_member = True
order_total = 45

print(is_member and order_total > 50)   # free shipping needs both
print(is_member or order_total > 50)    # a discount needs either
print(not is_member)
False
True
False

The Operators chapter covers these in depth, including how Python decides which side to check first.

Are True and False numbers in Python?

Surprisingly, yes. Under the hood, bool is a special kind of int: True behaves like 1 and False like 0.

print(True + True)
print(True == 1)
print(False * 10)
2
True
0

This has a genuinely useful trick: adding up a list of booleans counts how many are True.

attended = [True, False, True, True, False]
print("Days attended:", sum(attended))
Days attended: 3

Real-world example: a simple login check

Here's how booleans work together in a small login check. Each condition gets a clear name, and the final decision combines them.

saved_password = "blue-tiger-42"
typed_password = "blue-tiger-42"
failed_attempts = 1

password_ok = typed_password == saved_password
not_locked = failed_attempts < 3
can_log_in = password_ok and not_locked

print("Password correct:", password_ok)
print("Account unlocked:", not_locked)
print("Access granted:", can_log_in)
Password correct: True
Account unlocked: True
Access granted: True

Change failed_attempts to 3 and run it again: not_locked becomes False, so access is denied even with the right password.

Common mistakes with booleans

1. Writing true or false in lowercase

is_ready = true
NameError: name 'true' is not defined. Did you mean: 'True'?

Python is case-sensitive. Booleans must be written True and False.

2. Putting quotes around True or False

is_ready = "False"
print(bool(is_ready))
True

With quotes, "False" is a non-empty string, which is truthy. Drop the quotes: is_ready = False.

3. Using = instead of == in a condition

score = 10
if score = 10:
    print("Perfect!")
SyntaxError: invalid syntax. Maybe you meant '==' or ':=' instead of '='?

A single = assigns a value. To compare, use ==.

4. Writing == True when you don't need it

if is_open == True: works, but if is_open: says the same thing more simply. The variable is already a boolean.

Practice exercise

🏋️ Try it yourself

A movie theater lets you in if you are at least 13 years old or you are with an adult. Create variables age = 11 and with_adult = True, store the decision in can_enter, and print it. Then print how many of these quiz answers were correct: [True, True, False, True].

Show solution
age = 11
with_adult = True

can_enter = age >= 13 or with_adult
print("Can enter:", can_enter)

answers = [True, True, False, True]
print("Correct answers:", sum(answers))
Can enter: True
Correct answers: 3

What's next?

You now know how Python represents yes-or-no answers. Next, learn how to change values from one type to another, like turning the text "25" into the number 25, in Python type conversion.

Key takeaways

  • A boolean is either True or False, and its type is bool.
  • True and False are capitalized keywords with no quotes.
  • Comparisons such as 10 > 3 or name == "Ana" produce booleans.
  • bool() shows how Python sees a value: 0, 0.0, "", [], {}, None and False are falsy; almost everything else is truthy.
  • and needs both sides True, or needs at least one, and not flips the value.
  • True counts as 1 and False as 0, so sum() of a list of booleans counts the Trues.

Frequently asked questions

What are the two boolean values in Python?

True and False. Both start with a capital letter and are written without quotes.

What values are falsy in Python?

Zero (0 and 0.0), empty collections such as "", [] and {}, None and False itself. Every other value is treated as True.

Why is bool("False") True in Python?

bool() on a string only checks whether the string is empty. "False" contains text, so it is truthy. Only the empty string "" is falsy.

Is True equal to 1 in Python?

Yes. bool is a subclass of int, so True == 1 and False == 0. That is why sum() can count the True values in a list.

How do I convert a value to a boolean in Python?

Pass it to bool(), for example bool(0) gives False and bool("hi") gives True.