Python bool()

The bool() function converts a value to a Boolean expression, True or False .

If no parameter is given, by default the Boolean returns False. Boolean returns True if the parameter or value is True.

Syntax

bool([x])
x - is the value being evaluated by standard truth testing procedures.    

Example

# Returns False as x is False
x = 0
print(bool(x))
 
# Returns True as x is True
x = 1
print(bool(x))

# Returns False empty List
x = []
print(bool(x))

# Returns True as x is True
x = ['Python']
print(bool(x))

Output

False
True
False
True

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s