bool(object)
object :input any object 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
x=4
y=bool(x)
print(type(y)) # <class 'bool'>
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.