Boolean in Python

Booleans are operators that allow you to convey true or false statements. These are very important later on when we deal with control flow statements and logic. When you compare two values, the expression is evaluated and Python returns the boolean.

a = True

O/P – bool

When you run a condition in an if statement, Python returns True or False

print(89 > 73)
print(12 == 76)
print(34 < 98)

O/P –

Please read the previous topic for more understanding
Variables and Data Types
Number in Python
Python String
Python String Formatting

Boolean Evaluate Values and Variables

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

print(bool("Welcome to India"))

Output –



Almost any value is evaluated to True if it has some sort of content.
Any string is True, except empty strings.
Any number is True, except 0.
Any list, tuple, set, and dictionary is True, except empty ones.

Please download the example of Boolean in Python

Leave a Comment

Your email address will not be published. Required fields are marked *