Skip to main content

How to Check If a Value Counts as True or False in Python with bool()

· 3 min read
Jagdish Kumawat
Founder @ Dewiride

if items: and if name: work in Python even though items is a list and name is a string, because every value counts as either true or false. bool() shows you which. This guide tests seven common values, with real output from Python 3.15.2.

Syntax​

Syntax
bool(<value>)
PartWhat it means
<value>Any value: a number, a string, a list, None and so on
The resultTrue or False, the same answer if <value>: would act on

Python's documentation for bool: "Return a Boolean value, i.e. one of True or False. The argument is converted using the standard truth testing procedure." That procedure, truth value testing, lists the values that are false: "constants defined to be false: None and False", "zero of any numeric type", and "empty sequences and collections".

Prerequisites​

  • uv and Python. This guide uses uv 0.13.10 with Python 3.15.2, in a project made with uv init.

Step 1: Write the Script​

to_bool.py
for value in [1, 0, "yes", "", [3], [], None]:
print(repr(value), "->", bool(value))

The to_bool.py script in a macOS-style code window: a loop over 1, 0, yes, an empty string, a list with 3, an empty list and None prints each value with its bool.

  • The list pairs each kind of value with its empty or zero version: 1 and 0, "yes" and "", [3] and [], plus None.
  • repr(value) prints the value as you'd write it in code, so the empty string shows as ''.

Step 2: Run It​

Terminal
uv run python to_bool.py
Output
1 -> True
0 -> False
'yes' -> True
'' -> False
[3] -> True
[] -> False
None -> False

The output in a terminal: 1 is True, 0 False, yes True, the empty string False, the list with 3 True, the empty list False and None False.

Each pair split the same way: the value with something in it is True, its zero or empty version is False, and None is False. That's why if items: means "if the list isn't empty".

Common Mistakes​

MistakeWhat happensDo this instead
Converting text like "False" with bool()bool("False") is True: any non-empty string is trueCompare the text: text == "true"
Expecting bool("0") to be FalseIt's True: "0" is a non-empty stringConvert to a number first: bool(int("0"))
Expecting a string of spaces to be falsebool(" ") is TrueStrip it first: bool(text.strip())

Troubleshooting​

SymptomLikely causeFix
A setting read from a file or form is always TrueThe text was passed to bool()Compare the text with the words you accept

FAQ​

Is 0.0 false too?​

Yes: bool(0.0) is False. The documentation counts "zero of any numeric type" as false.

Do I need bool() inside an if?​

No. if value: already tests the value this way. Use bool() when you want to keep or print the result.

Conclusion​

bool() showed the rule behind if value:: 1, "yes" and [3] are true, while 0, "", [] and None are false.

Additional Resources​