Python - Data Type bool type

Introduction

Python Boolean type bool augments the notions of true and false in Python.

The built-in words True and False are just customized versions of the integers 1 and 0.

It is as if these two words have been preassigned to 1 and 0 in Python.

When used explicitly in truth test code, the words True and False are equivalent to 1 and 0, but they make the programmer's intent clearer.

Results of Boolean tests run interactively print as the words True and False, instead of as 1 and 0, to make the type of result clearer.

You are not required to use only Boolean types in logical statements such as if.

All objects are inherently true or false.

Python also provides a bool built-in function that can be used to test the Boolean value of an object if you want to make this explicit.

Demo

print( bool(1) )
print( bool('test') )
print( bool({}) )

Result

Related Topic