As part of our Python documentation I introduce the bool() function in Python.
The bool() function in Python implements default truth testing for converting an input argument into a Boolean value. The function returns the converted Boolean value.
The bool() function in Python takes a single (optional) parameter as input argument. If no parameter (no input) was provided to the function it will return the default value False.
The bool() function returns False in the following cases:
- False as input argument value
- None is passed as input argument value
- Empty sequence passed, e.g. [] or ()
- Zero as input argument value, e.g. 0.0 or 0
- Passing an empty mapping, e.g. {}
- Objects with _bool()_ or _len()_ returning 0 or False, if object is instance of a class that contains these methods
In all other cases the bool() function will return True.
Data scientist focusing on simulation, optimization and modeling in R, SQL, VBA and Python
Leave a Reply