The bool() method takes a specified argument and returns its boolean value.
Example-
bool() Syntax
The syntax of bool() is:
bool(argument)
bool() Parameter
The bool() method takes in a single parameter:
- argument - whose boolean value is returned
bool() Return Value
The bool() method returns:
False- if argument is empty, False, 0 or NoneTrue- if argument is any number (besides 0), True or a string
Example 1: Python bool() with True Arguments
Output
254 is True 25.14 is True Python is the best is True True is True
In the above example, we have used the bool() method with various arguments like integer, floating point numbers, and string.
Here, the method returns True values for arguments like 25, 25.14, 'Python is a String', and True.
Example 2: bool() with False Arguments
Output
[] is False 0 is False None is False False is False
In the above example, the bool() method returns False values for arguments like 0, None, False and [].
Recommended Readings: