The bool()
function is used to convert any value to a Boolean value (True
or False
). It returns False
if called without any argument or the given argument has a boolean value of False
, otherwise it returns True. In other words, it converts any given non-Boolean value to a Boolean value.
bool(obj)
obj |
The object whose boolean value should be evaluated. |
The function returns the boolean value( True
or False
) of the specified object.
In a nutshell the boolean value of the data types can be summarized as:
non-zero number e.g 1, -7, 20.0 | True |
Zero e.g 0, 0.0, 0j | False |
non-empty String | True |
empty string | False |
nonempty sequence e.g |
True |
empty sequence e.g () , [] , {} |
False |
any other instance of Python type except Nonetype e.g class, function, types |
|
None | False |