This bool()
function returns an expression converted into a Boolean.
bool(expression)
Here,
False
or omitted, this function returns False
; otherwise, it returns True
.Note: bool()
always returns True
, unless:
>>> 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.