What Is a Boolean in Coding? (It's Just True or False — and It Controls Everything)
A boolean is the simplest thing in all of coding.
It can only be one of two values: True or False.
That's it. Two options. No middle ground.
And yet it's the logic underneath every game, every app, and every AI decision you've ever encountered.
▶️ Watch the 60-second version on YouTube Shorts
Where Does the Name Come From?
The word "boolean" comes from George Boole — a 19th-century mathematician who built an entire system of logic using only two values: true and false.
Computers turned out to be perfect for this. At the hardware level, everything is ones and zeros — on or off. Booleans are just that idea dressed up for programming.
You don't need to remember who George Boole was. But it's a solid pub fact.
What a Boolean Looks Like in Python
In Python, booleans use a capital letter:
is_raining = True
has_key = False
game_over = True
Two possible values: True or False. That's all. (Lowercase true is an error in Python — the capital matters.)
Where Booleans Actually Show Up
You've already used booleans without realising it. Every if statement relies on one:
game_over = False
if game_over:
print("Thanks for playing!")
The if statement asks: is this True? Yes → run the block. No → skip it.
You can also use a boolean as a flag — a switch that tracks whether something has happened:
found_exit = False
for room in dungeon:
if room == "exit":
found_exit = True
break
if found_exit:
print("You escaped!")
else:
print("Still stuck in there.")
found_exit starts as False and flips to True the moment the exit is found. Simple, readable, and exactly how game logic works in real builds.
Comparisons Give You Booleans
Any comparison in Python returns a boolean:
score = 95
print(score > 90) # True
print(score == 100) # False
print(score != 0) # True
This is why comparisons and if statements fit together so naturally — comparisons produce booleans, and if statements consume them.
Combining Booleans: and, or, not
Python gives you three ways to combine booleans:
is_logged_in = True
has_permission = False
# and — both must be True
if is_logged_in and has_permission:
print("Access granted")
# or — at least one must be True
if is_logged_in or has_permission:
print("Partial access")
# not — flips True to False (and vice versa)
if not game_over:
print("Keep playing!")
This is where booleans get powerful. You can chain conditions to express real logic — "let me in if I'm logged in AND I have permission" — in a single readable line.
A Real Example: The Farmer's Harvest Check
In the Farmer AI series, the drone checks whether a crop is ready before it harvests. That check returns a boolean:
def is_ready_to_harvest(crop):
return crop.growth == 1.0
if is_ready_to_harvest(current_crop):
harvest()
else:
move_on()
is_ready_to_harvest() returns True or False. The if statement acts on it. That's booleans doing real work in real code.
Functions that return booleans like this are called predicate functions — one of the most useful patterns you'll write once you get comfortable with them.
What Pairs With Booleans Next?
Booleans don't live in isolation. Here's where they connect to everything else:
- If / else — the most direct use of a boolean → What Is an If Statement?
- Loops —
while game_over == False:keeps a game running until the boolean flips → What Is a Loop? - Functions — write a function that returns
TrueorFalseand you can reuse that check anywhere → What Is a Function?
One concept. Two states. Everything else builds from here.