Python bool() Method

The bool() method converts a value to the bool class object containing either True or False.

Syntax:

bool(value)

Parameters:

value: (Optional) The value to be converted to boolean.

Return Value:

Returns True for truthy value else returns False for falsy value 0, None, False, or ''

The following example converts values into boolean values.

Example:
value = [0]
print("Boolean of [0] is: ", bool(value))

value = 0
print("Boolean of 0 is: ", bool(value))

value = 1
print("Boolean of 1 is: ", bool(value))

value = -1
print("Boolean of -1 is: ", bool(value))

value = None
print("Boolean of None is: ",bool(value))

value = True
print("Boolean of True is: ", bool(value))

value = False
print("Boolean of False is: ", bool(value))

value = 'a string'
print("Boolean of a string is: ", bool(value))
Output
Boolean of [0] is:  True
Boolean of 0 is:  False
Boolean of 1 is:  True
Boolean of -1 is:  True
Boolean of None is:  False
Boolean of True is:  True
Boolean of False is:  False
Boolean of a string is:  True