Python: bool() function
bool() function
The bool() function is used to convert a value to a Boolean.
Syntax:
class bool([x])
Version:
(Python 3.2.5)
If x is false or omitted, this returns False; otherwise it returns True. bool is also a class, which is a subclass of int. Class bool cannot be subclassed further. Its only instances are False and True.
Return value:
Boolean Values (True/False).
Example: Python bool() function
Output:
val = True val = False val = True val = False val = False
Check if a list is empty or not ?
Output:
List is empty. List is not empty.
Python Code Editor:
Previous: bin()
Next: bytearray()
Test your Python skills with w3resource's quiz