bool(): Get Boolean Constant Function

1 Description

The Python bool function will convert the supplied parameter to a boolean type. There are two boolean types, True and False.

The bool function will return True for any object passed to it. In order for the bool function to return False you must pass one of the following things to the bool function.

  1. The constant None
  2. The constant False
  3. The integer value zero: 0
  4. The float value zero: 0.0
  5. The numeric_j value zero: 0j
  6. The Decimal value zero: Decimal(0)
  7. The Fraction value zero: Fraction(0, 1)
  8. An empty string: ''
  9. An empty tuple: ()
  10. An empty list: []
  11. An empty dictionary: {}
  12. An empty set: set()
  13. An empty range: range(0)
  14. An object which defines a __bool__() method which returns False when called
  15. An object which defines a __len__() method which returns zero (0) when called

This document was last updated: