Python

Important Statements

Exception handling

The assert Statement

Used for debugging. Tests a condition, and if the condition is false, it raises an AssertionError.

assert condition, message

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))