Assert Statements

Debugging with assertions

Interview Relevant: Debugging techniques

Assert

Verify conditions during development.

Code Examples

python
1def discount(price, percent):
2    assert 0 <= percent <= 100, "Invalid discount"
3    return price * (1 - percent/100)

AI Tutor

Ask about the topic

Sign in Required

Please sign in to use the AI tutor

Sign In