Learn Python
>>> variables_data_types.booleans

Booleans in Python

#concept

bool is Python's type for True and False — used everywhere a yes/no decision needs representing, especially in if statements and loop conditions. Under the hood, bool is actually a subtype of int: True behaves as 1 and False behaves as 0 in arithmetic, though it's best treated as its own logical type in normal code rather than relied on as a number.

#how it works
1

Exactly two values

True and False, always capitalized — there is no third option.

2

Comparisons always produce a boolean

==, <, >, and similar operators evaluate to True or False.

3

Every value has inherent truthiness

Used implicitly anywhere a boolean is expected, most commonly in if conditions.

4

Falsy values

0, 0.0, "", None, and any empty collection are all treated as falsy; almost everything else is truthy.

5

bool(x) makes it explicit

Converts any value to True or False directly, applying the same truthiness rules.

#example
print(True + True)
print(5 > 3)
print(bool(""))
print(bool("hello"))
print(bool([]))
Output
2
True
False
True
False
1True + True treats each True as 1, giving the integer 2 — proof that bool really is a subtype of int under the hood.
25 > 3 is a comparison, which always evaluates to a boolean.
3bool("") is False — an empty string is one of the falsy values.
4bool("hello") is True — any non-empty string is truthy.
5bool([]) is False — an empty list is falsy too, just like an empty string.
#use cases
Writing conditions in if statements and while loops, which rely on truthiness constantly
Checking whether a list, string, or dictionary is empty with a plain if my_list: instead of comparing its length
Flags and settings in code, like is_active or has_permission
Short-circuit logic with and / or, which return one of the original values based on truthiness, not just True or False

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Re-implement each visualized algorithm in Python yourself — building beats watching.