[Link].
com
Python Booleans
1. Introduction to Booleans
• Booleans represent one of two values:
o True
o False
• Booleans are often used in conditions, loops, and logical operations.
2. Boolean from Comparison Operators
• Comparisons return Boolean values.
3. Truthy and Falsy Values
• The following are considered Falsy:
o 0, 0.0
o None
o False
o '' (empty string)
o [ ], {}, () (empty list, dict, tuple)
1
[Link]
• All other values are Truthy.
4. Boolean from Built-in Class bool()
• Convert values to Boolean using bool().
5. Boolean Operators
• Logical operators return Boolean values:
o and, or, not
2
[Link]
• The and returns the first falsy value it encounters. If both values are
truthy, it returns the second value.
• The or operator returns the first truthy value it finds. If both are falsy, it
returns the last one.
3
[Link]
• Membership operators in and not in also return Boolean values.