bool() Method Syntax
bool([x])
Parameters
- x: Any object that you want to convert into a boolean data type.
Return
It can return one of the two values.
- It returns True if the parameter or value passed is True.
- It returns False if the parameter or value passed is False.
Here are a few cases, in which Python’s bool() method returns false. Except these all other values return True.
- If a False value is passed.
- If None is passed.
- If an empty sequence is passed, such as (), [], ”, etc.
- If Zero is passed in any numeric type, such as 0, 0.0, etc.
- If an empty mapping is passed, such as {}.
- If Objects of Classes having __bool__() or __len()__ method, returning 0 or False.
bool() in Python
Python bool() function is used to return or convert a value to a Boolean value i.e., True or False, using the standard truth testing procedure.
Example
Python3
x = bool ( 1 ) print (x) y = bool () print (y) |
Output
True False