Conditional checks
Validate whether an optional value, collection, or configuration field is present before branching.
Python · Class
bool() converts an object through Python’s standard truth-testing procedure and returns True or False. With no argument it returns False; bool is an int subclass with only the two instances True and False.
Calling bool() applies Python's standard truth-testing rules and produces one of the two Boolean objects. With no argument it produces False; the type is also an int subclass, cannot be extended by subclassing, and has only True and False as instances.
class bool(object=False, /)| Name | Type | Description |
|---|---|---|
object | object=False, positional-only | Object to convert using standard truth testing; omitting it is equivalent to a false value. |
A bool value: True when the argument is truthy, otherwise False.
value = "ready"
if bool(value):
print("truthy")
print(bool([]))
print(bool(0))The non-empty string is true, while an empty list and zero are false.
Validate whether an optional value, collection, or configuration field is present before branching.
Normalize inputs into an explicit Boolean for a flag, predicate result, or serialized state.
Apply Python's truth-testing behavior to custom objects that define __bool__() or __len__().
bool() returns either True or False after applying standard truth testing to its argument. Omitting the argument returns False.
Follow-up: What controls truth testing for a user-defined object? Its class can define __bool__(); if that is absent, Python can use __len__() to determine truth.
bool is a subclass of int, so Boolean values can behave like 0 and 1 in numeric contexts. Despite that relationship, the documented Boolean instances are only False and True.
Follow-up: How should code make numeric intent explicit? Convert with int() rather than relying on Boolean-to-integer behavior.
The built-in bool type cannot be subclassed further. It has exactly two constant instances: True and False.
Follow-up: What values are false in Boolean contexts? False, None, numeric zero, and empty strings or containers are interpreted as false.
TrueFalseintandornot__bool____len__