The statement assert exists in almost every programming language.
- Assert helps early detection of the problem in program,
- Assert also acts as documentation for other developers, indicating that its condition holds from now on.
- We do not use parentheses to call assert like a function, Assert is a statement.
- Also assertions can include optional messages also.
- Inform developers about unrecoverable errors in a program.
- Assertions work by declaring some conditions as impossible in your code thus acting as self-checks.
- If there is a bug the assert statement will tell you what exactly is the impossible condition that was triggered. In this way once can easily fix the code and helps to fix bugs.
Wrong way to use assert:
assert(2 + 2 == 5, "There we have a problem")
Right way to use assert
assert 2 + 2 == 5, "There we have a problem"
Thus, we do not use parentheses with assert statement.
Hope this helps.