Booleans
Booleans represent truth values. Python has two boolean values: True and False.
Boolean Values
Loading Python Playground...
Boolean from Comparisons
Comparisons return boolean values:
Loading Python Playground...
Exercises
Loading Python Exercise...
Loading Python Exercise...
Loading Python Exercise...
Truthy and Falsy Values
Python treats some values as True or False in boolean context:
Loading Python Playground...
Loading Python Exercise...
Loading Python Exercise...
Boolean Operations
Loading Python Playground...
Practical Example
Loading Python Playground...
Loading Python Exercise...
Practice Playground
Loading Python Playground...
Key Takeaways
- Booleans are
TrueorFalse(capitalized) - Comparisons (
>,<,==,!=) return booleans - Use
and,or,notfor boolean logic - Empty values are "falsy", non-empty are "truthy"
bool()converts values to boolean

