Boolean Data Type

The Boolean data type is one of the basic and important data types in Python. It is used to represent one of two possible values: True or False. These two values are mainly used in decision making and logical operations within a program.

Boolean values help programs make decisions, control the flow of execution, and perform comparisons.

WHAT IS A BOOLEAN VALUE

A Boolean value can only be:

True
False

In Python, both True and False must start with a capital letter. Writing true or false in lowercase will cause an error.

Example:

is_active = True
is_logged_in = False

BOOLEAN IN COMPARISON OPERATIONS

Boolean values are commonly created using comparison operators. When you compare two values, Python returns either True or False.

Examples:

print(5 > 3)
Output will be True

print(10 == 5)
Output will be False

Common comparison operators:

Greater than >
Less than <
Equal to ==
Not equal to !=
Greater than or equal to >=
Less than or equal to <=

BOOLEAN IN CONDITIONAL STATEMENTS

Boolean values are mainly used in decision making statements such as if conditions.

Example:

age = 18

if age >= 18:
print(“You are eligible to vote”)

If the condition is True, the code inside the block will run.

BOOLEAN WITH LOGICAL OPERATORS

Python also provides logical operators to combine conditions.

and returns True if both conditions are True
or returns True if at least one condition is True
not reverses the Boolean value

Example:

print(5 > 3 and 10 > 5)
Output will be True

BOOLEAN USING bool FUNCTION

You can convert values into Boolean using the bool() function.

Example:

print(bool(1))
Output will be True

print(bool(0))
Output will be False

In Python, empty values such as 0, empty string, or empty list are considered False. Most other values are considered True.

WHY BOOLEAN IS IMPORTANT

The Boolean data type is essential for controlling program logic. It allows your program to make decisions, repeat actions, and validate conditions.

Understanding Boolean values is a key step in learning conditional statements, loops, and building intelligent Python applications.

Home » PYTHON FUNDAMENTALS (PYF) > Variables and Data Types > Boolean Data Type