Python bool()
Python bool() Function
Last Updated : 17 Mar 2025
The bool() function is one of the built in methods in python which outputs the Boolean value depending on the input parameters. The Boolean values True or False are returned from the single argument. The python bool() method converts value to boolean (True or False) using the standard truth testing procedure.
Python bool() Function Syntax
It has the following syntax:
Parameters
It is not mandatory to pass value to bool(). If you do not pass the value, bool() returns False.
In general , bool() takes a single parameter value.
Return
The bool() returns:
- Returns False if the value is omitted or false and the condition is not met.
- Returns True if the value is true and condition is met.
Python bool() Function Example 1
Let us take an example to demonstrate the bool() function in Python.
Output:
[] is False [] is False [0] is True 0.0 is False None is False True is True Easy string is True
Python bool() Function Example 2
Let's take anothe example to demonstrate the bool() function with if-else statements in Python.
Output:
number is less than or equal to 15
Explanation:
In the above code, If the condition is true or false, the respective block is executed.
Now, lets see the explicit conversion of value into Boolean value in the below example.
# Using bool() function to convert the condition to a boolean value
Example:
Output:
number is less than or equal to 15
Python bool() Function Example 3
1. Using bool() function to check if a value is True or False
Example:
Output:
2. To Check if an empty string is True or False
Example:
Output:
3. To Check if a zero value is True or False
Example:
Output:
Conclusion:
All in all, the bool() function is a useful asset in Python for working with boolean values. It very well may be utilized to switch any value over completely to a boolean value expressly, and it can likewise be utilized to check in the event that a value is true or false.