Booleans datatype
• 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:
• print(10 > 9)
print(10 == 9)
print(10 < 9)
• Try it Yourself »
Evaluate Values and Variables
• print(bool("Hello"))
print(bool(15))
• Try it Yourself »
• x = "Hello"
y = 15
print(bool(x))
print(bool(y))
• 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 are True, except empty ones.
• there are not many values that evaluate to False, such as (), [], {}, "", the
number 0, and the value None. And of course the value False evaluates to
False.
• bool("abc")
• bool(123)
• bool(["apple", "cherry", "banana"])
• bool(False)
bool(None)
bool(0)
bool("")
bool(())
bool([])
bool({})