bool(): converts a given value to a Boolean (either True or False)

bool(object)
object :input any object
Returns boolean vlaue ( True or False )

Examples

x=10
y=bool(x)
print(y) # True 
x='12'
y=bool(x)
print(y) # True
x='' # empty string
y=bool(x)
print(y) # False 
x=0  
y=bool(x)
print(y) # False
x=1
y=bool(x)
print(y) # True
x=[] # empty list
y=bool(x)
print(y) # False
x=() # empty tuple
y=bool(x)
print(y) # False
x={} # empty set
y=bool(x)
print(y) # False
x=None
y=bool(x)
print(y) # False 

Bool data type

We can use type() to know more about boolean data type.
x=4
y=bool(x)
print(type(y)) # <class 'bool'>


bool() will return False for following inputs
empty string
empty list
any empty iterable object
None
0
False


All Built in Functions in Python

max() Bitwise operators using bin() any()




Subscribe to our YouTube Channel here



plus2net.com







Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2026   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer