Python bool() function
Convert a value to True or False.
Syntax
bool(x=False)
False for 0, 0.0, empty strings and collections, and None; True for everything else. This is the same rule if uses.
Parameters
| x | any value |
Return value
bool
Example
Code
print(bool(0), bool(42), bool(-1)) print(bool(""), bool("False"), bool(" ")) print(bool([]), bool([0]), bool(None))
Output
False True True False True True False True False
Good to know.
bool("False") is True: any non-empty string is truthy.Related
Learn it step by step in the free lesson Making Decisions, with exercises that check your answers.