assert StatementUsed for debugging. Tests a condition, and if the condition is false, it raises an AssertionError.
assert condition, message
condition: An expression that should be true for the program to continue correctly.message: An optional string that will be included with the AssertionError if the condition is false.Example:
def divide(a, b):
assert b != 0, "Denominator cannot be zero"
return a / b
# This will work:
print(divide(10, 2))
# This will raise an AssertionError:
print(divide(10, 0))
condition is True, nothing happens.condition is False, an AssertionError is raised, optionally with the provided message.assert statements are typically removed or ignored when Python is run in optimized mode (python -O).