/  Bool() method in Python Built in Function

Bool() method in Python Built in Function

 

The bool method in built function returns the Boolean value as TRUE or FALSE depending upon the given number in the argument.

 

Syntax

bool([x]

 

Table for Bool where values are considered False

InputOutput Value
If zero is the value of any numeric typeFor e.g. Integer=0, Float=0.0 or Complex number= 0j
In any empty sequenceList=[], tuple (), string “”
In case of empty mapping{}
Classes which has bool or lengthFalse or 0

 

Example-1:

 

Use of bool by Tuple

x = bool()
print(x)

 

Output:

Bool() method in PythonBuilt in Function

 

Example-2:

 

Use of bool in List

x = bool([])
print(x)

 

Output:

Bool() method in PythonBuilt in Function

 

Example-3:

 

Use of bool in empty string

x = bool("")
print(x)

 

Output:

Bool() method in PythonBuilt in Function

 

Example-4:

 

Use of bool in numeric type

x = bool (0)
print(x)

 

Output:

Bool() method in PythonBuilt in Function

 

Example-5:

 

Use of bool in None value

test = None
print(test,'is',bool(test))

 

Output:

Bool() method in PythonBuilt in Function

 

Example-6:

 

Use of bool in TRUE value

x = True
print(x,'is',bool(test))

 

Output:

Bool() method in PythonBuilt in Function

 

Example-7:

 

Use of bool in string

x = 'My name'
print(x,'is',bool(test))

 

Output:

Bool() method in PythonBuilt in Function