What are Booleans? Booleans are two opposite values: either True or False.
The tutorial provides examples about writing Boolean statements in Python.
Example 1: How to write to a simple Boolean statement
The following shows a simple Python code.
print(1>2)
print(1==1)
The following is the output.
False True
Example 2: How to use bool() to write Boolean statements
The following code example shows how you can use the bool() to write Boolean statements.
print (bool(1))
print(bool(0))
print(bool("hello world"))
The following is the ouput.
True False True
Beside bool(0), there are other statements resulting in False as well. The following lists them.
print(bool(""))
print(bool(False))
print(bool(None))
print(bool(()))
print(bool([]))
print(bool({}))
The result is as follows.
False False False False False False