Introduction

Python boolean type is one of the built-in data types provided by Python, which represents one of the two values i.e. True or False. Generally, it is used to represent the truth values of the expressions. For example, 1==1 is True whereas 2<1 is False.

Boolean Values

In programming you often need to know if an expression is True or False.
You can evaluate any expression in Python, and get one of two answers, True or False.
When you compare two values, the expression is evaluated and Python returns the Boolean answer.

a = 0
b = 1
print(a==b) ## returns False
print(a!=b) ## returns True

Evaluate Values and Variables

The bool() function allows you to evaluate any value, and give you True or False in return.

a = bool("hello")
print(a)
print(bool(0))
print(bool(10))
print(bool(-0))

Conditions for True and False

A number 0,empty String "",empty list[] or empty tuple()-this type only returns False.Except this all values returns True

x = bool("")
print(x) ## False
print(bool(0)) ## False
print(bool([])) ## False
print(bool(())) ## False
print(bool({})) ## False
print(bool(1.444)) ## True