Python’s bool() does not read a string’s words: bool("False") is True because the string is non-empty. To check whether text represents a boolean, define which words your program accepts, convert those explicitly, and reject anything else.
Why bool("False") is True
bool() performs a truth-value test; it does not parse text as a boolean. An empty string is false, while every non-empty string is true, regardless of its contents. So bool("") is False, but bool("False"), bool("no"), and bool("0") are all True. The Python 3.13 argparse documentation specifically cautions against using bool() as a type converter for this reason.
Parse only the boolean words your input specification allows
If the accepted values are the words true and false, compare against those values directly. This parser ignores letter case and surrounding whitespace, but rejects other text:
def parse_bool(value: str) -> bool:
normalized = value.strip().casefold()
if normalized == "true":
return True
if normalized == "false":
return False
raise ValueError(f"Expected 'true' or 'false', got {value!r}")
For example, parse_bool(" TRUE ") returns True, and parse_bool("False") returns False. Values such as "yes", "0", or "maybe" raise ValueError unless you choose to support them.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
#1 Best Overall
Choose and document the vocabulary
There is no universal set of boolean words that every Python application must accept. If your interface should accept alternatives such as yes/no, 1/0, or on/off, add each token deliberately and map it to the intended value. Python’s argparse documentation describes choices as useful when an argument accepts a fixed set of values.
Reject invalid input rather than silently treating it as false
Returning False for every unrecognized string makes typos and malformed input look valid. Raise a clear exception, as above, or use another explicit result that lets the caller distinguish invalid input from a valid false value.
Rank #2
For command-line flags, use argparse actions
When a command-line option is enabled simply by appearing, use store_true rather than asking the user to supply the word true or false:
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--verbose", action="store_true")
args = parser.parse_args()
With this setup, --verbose sets args.verbose to True; leaving out the option sets it to False. The store_false action provides the inverse behavior. These actions are documented in the Python 3.13 argparse reference.
Free tools Windows power users keep installed
One-click scans. No signup required.
Offer positive and negative spellings
argparse.BooleanOptionalAction, available in Python 3.9 and later, creates positive and negative forms such as --feature and --no-feature. They set the destination to True and False, respectively. Check your project’s minimum supported Python version before using it.
When the command line must accept a text value
If users need to write an argument such as --enabled false, pass the supplied text through a validating parser with a documented vocabulary, or constrain it to fixed choices and convert it explicitly. Do not use type=bool: the non-empty string false converts to True, not False.
Quick Recap
Best Value
Choose based on what the input means
| Input situation | Use | Behavior |
|---|---|---|
| Whether a CLI option was included | argparse store_true or store_false |
Sets a boolean based on flag presence. |
| A CLI option with positive and negative forms | argparse.BooleanOptionalAction |
Provides forms such as --feature and --no-feature; requires Python 3.9 or later. |
| Text that encodes a boolean | An explicit parser or fixed choices followed by conversion | Accepts only the tokens you define and can reject invalid text. |
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




