ScanSkill

bool

This bool() function returns an expression converted into a Boolean.

Syntax

bool(expression)

Here,

  • expression: Required. If the expression(or object) is False or omitted, this function returns False; otherwise, it returns True.

Note: bool() always returns True, unless:

  • The expression(or object) is empty, like [], (), {}
  • The expression(or object) is False
  • The expression(or object) is 0
  • The expression(or object) is None

Examples

>>> bool(1)
True
>>> bool(0)
False
>>> bool("False")
True
>>> bool([0, 0])
True
>>> bool([])
False
>>> bool(2+2)
True

Here, bool() has returned False, only when the expression(or object) is either empty or 0.

Parameter Values

  • expression → Any object like string, list, number, etc.