Tutorial Study Image

Python bool()

The bool function in python takes a value as input and returns its boolean value ie; either True or False as per boolen convention.


bool([value]) #where value any object,like String,List,Number etc.
 

bool() Parameters

The bool function takes only a parameter. If a value is passed as a parameter, its equivalent boolean value will be returned as either True or False.

Parameter Description Required / Optional
Value or empty Bool takes only a parameter if no parameter passed return False Optional

bool() Return Value

On passing any other inputs rather than the ones mentioned in the table, returns True.

Input Output
None False
False False
Numeric having value equivalent to zero False
Empty iterables like (),{},[] etc False
Classes having __len__ or __bool__ methods returning 0/False False

bool() Examples

Passing String as a parameter

eg_string = ‘0’
print(bool(eg_string))

Output:

True

Passing an iterable with False iterable

iterable = [False]
print(bool(iterable))

Output:

True

Passing an empty iterable

empty_iterable = []
print(bool(empty_iterable))

Output:

False