Boolean in Python

Boolean or bool is a data type with two possible values, 0 (False) or 1 (True).

When we compare two values, the expression is evaluated and Python returns the answer in the form of Boolean:
print(5>1)
The condition or expression (5>1) is valid so, Python return the answer as True.

Output will be
True


Rules of Boolean values:
(i) Almost any value is evaluated to True if it has some sort of content.
(ii) Any string is True, But empty strings is False.
(iii) Any number is True, But 0 return False.
(iv) Any list, tuple, set, and dictionary are True, except empty ones.

For Example -
name="Neoogy"
age=0
print(bool(name))
print(bool(age))

Output will be
True
False


0 Comments