What Is a Boolean in Python?
A Boolean in Python is a value that can only be True or False.
Beginners see Booleans very early because Python uses them to make decisions. For example, a program might check whether a user is logged in, whether a number is greater than another number, or whether a list has any items.
If you are new to Python, this page will help you understand what Booleans are, where they come from, and how they are used in simple if statements.
What a Boolean means
A Boolean is a data type in Python with only two possible values:
TrueFalse
You can think of a Boolean as a yes/no answer:
- yes / no
- on / off
- true / false
Booleans are used when Python needs to check a condition.
For example:
- Is
5greater than3? - Is a user logged in?
- Does a list contain any items?
The answer to each of these is either True or False.
Also note that Python is case-sensitive:
Trueis correctFalseis correcttrueandfalseare not correct in Python
Boolean values in Python
Python has two built-in Boolean values:
TrueFalse
These are not strings. That means:
Trueis a Boolean value"True"is a string
That difference is important.
You can check the type of a Boolean with type():
print(type(True))
print(type(False))
Output:
<class 'bool'>
<class 'bool'>
The Boolean type in Python is called bool.
Here is a simple example:
is_logged_in = True
has_items = False
print(is_logged_in)
print(has_items)
print(type(is_logged_in))
Output:
True
False
<class 'bool'>
How Booleans are created
One common way to create a Boolean is with a comparison.
Comparisons ask a question and return True or False.
print(5 > 3)
print(2 == 4)
print(10 != 7)
Output:
True
False
True
In these examples:
5 > 3means “is 5 greater than 3?”2 == 4means “is 2 equal to 4?”10 != 7means “is 10 not equal to 7?”
You can also store comparison results in variables:
is_adult = 20 >= 18
print(is_adult)
Output:
True
Functions can return Booleans too. You will see this often as you learn more Python.
Expressions inside Python if statements are also checked as true or false. That is how Python decides which block of code to run.
If you want a fuller beginner lesson, see Python Booleans explained: True and False.
Where beginners use Booleans
Beginners usually use Booleans in a few common places.
In if statements
Booleans are very common in if statements because they control program flow.
age = 18
if age >= 18:
print("You are an adult.")
Output:
You are an adult.
The comparison age >= 18 returns a Boolean. If it is True, the code inside the if block runs.
In while loops
Booleans can also control whether a loop keeps running.
running = False
while running:
print("This will not print.")
Because running is False, the loop does not run.
In variables
Booleans are often stored in clearly named variables such as:
is_logged_inhas_itemsis_ready
Example:
has_items = True
if has_items:
print("Your cart has items.")
Output:
Your cart has items.
When checking conditions
Booleans are useful when checking things like:
- equality
- size
- existence
For example:
name = "Sam"
print(name == "Sam")
print(len(name) > 0)
Output:
True
True
Boolean examples to include
Here are a few simple Boolean examples in one place.
Assign True and False to variables
is_open = True
is_closed = False
print(is_open)
print(is_closed)
Use a comparison like age >= 18
age = 16
can_vote = age >= 18
print(can_vote)
Output:
False
Use a Boolean in an if statement
is_member = True
if is_member:
print("Welcome back!")
Output:
Welcome back!
Show type(True) output
print(type(True))
Output:
<class 'bool'>
Common beginner confusion
A few Boolean mistakes are very common when you are starting out.
True is not the same as "True"
This is a very important difference:
print(True)
print("True")
print(type(True))
print(type("True"))
Output:
True
True
<class 'bool'>
<class 'str'>
They may look similar when printed, but they are different types.
False is not the same as 0
In some Python contexts, False is related to 0, but they are not the same thing conceptually.
print(False == 0)
print(type(False))
print(type(0))
Output:
True
<class 'bool'>
<class 'int'>
As a beginner, it is best to think of:
Falseas a Boolean value0as a number
Use == to compare, not =
This is a very common mistake.
=assigns a value==compares two values
Correct:
age = 20
if age == 20:
print("Age is 20")
Wrong:
# if age = 20:
# print("Age is 20")
The wrong version causes an error because = cannot be used for comparison inside an if condition.
Python keywords are case-sensitive
These are correct:
TrueFalse
These are wrong:
truefalse
Common mistakes
These problems often confuse beginners:
- Writing
trueorfalsein lowercase - Using strings like
"True"when a real Boolean is needed - Using
=instead of==in a condition - Assuming every non-empty value is literally
Trueinstead of just truthy
If something is not working, these quick checks can help:
value = "hello"
print(value)
print(type(value))
print(5 > 3)
print(bool(0))
print(bool("hello"))
Output:
hello
<class 'str'>
True
False
True
These lines help you check:
- the actual value
- the type of the value
- whether an expression returns a Boolean
- how
bool()converts values
To learn more about this conversion, see the bool() function explained.
FAQ
What is a Boolean in Python in simple words?
A Boolean is a value that can only be True or False.
Is True a string in Python?
No. True is a Boolean value. "True" is a string.
How do I make a Boolean in Python?
You can assign True or False directly, or create one with a comparison like 10 > 5.
What is the Boolean type in Python?
The Boolean type is bool.
Where are Booleans used?
They are used in if statements, loops, comparisons, and functions that return yes/no results.