Python Boolean

A boolean is a value that is either True or False. When two values are compared, the expression is evaluated and a boolean value is returned.

Example

print(70 > 50)
print(55 < 19)
print(10 == 10)
  
Output
True
False
True

A boolean is commonly used with control statements to determine the flow of a program.

Example:

x = 10
y = 20
if x > y:
    print("x is greater than y")
else:
    print("y is greater than x")
  
Output
y is greater than x

Evaluate Values to Return Boolean

The bool() function evaluates any value and return True or False.

Example

print(bool("hello"))
print(bool(1 > 0))
print(bool(10))
print(bool("abc"))
print(bool(0))
print(bool(None))
print(bool(False))
print(bool(""))
print(bool([]))
print(bool({}))
print(bool(()))
  
Output
True
True
True
True
False
False
False
False
False
False
False