# PITFALL 1: assert with a tuple is always True!
# assert(condition, "message") <-- WRONG! This isassert (tuple,)
# assert condition, "message" <-- RIGHT
try:
x = -1assert x > 0, "Must be positive"except AssertionError as e:
print(f"Caught: {e}")
# Tuple form is always truthy (non-empty tuple)
value = (False, "this is always truthy")
print(f"Tuple truthiness: {bool(value)}")
# PITFALL 2: assert is a statement, not a function# These are different:
# assert(False, "msg") -> asserts a non-empty tuple (always True!)
# assertFalse, "msg" -> asserts Falsewith message "msg"# Demonstrate the differencetry:
assertFalse, "correct usage"except AssertionError as e:
print(f"Correct: {e}")
Output
Click "Run" to execute your code
The most common assert pitfall is writing assert(cond, msg) with parentheses — this creates a non-empty tuple which is always truthy. Use assert cond, msg without parens.
Challenge
Try modifying the code above to explore different behaviors. Can you extend the example to handle a new use case?