Booleans represent True/False values and are fundamental to all conditional logic in programming.
TrueandFalse(note the capitalization)- Result of comparisons:
5 > 3returnsTrue - Result of logical operations
and- both must be Trueor- at least one must be Truenot- reverses the value
Values that are considered False:
False,None,0,0.0,"",[],{},set()
Everything else is considered True.
==equal,!=not equal<,<=,>,>=is(identity),in(membership)
- Use parentheses for complex conditions
- Take advantage of short-circuit evaluation
- Remember that
=assigns,==compares - Empty collections are falsy, non-empty are truthy