+ 3
Can you explain me the concept of assertion and its use in python
6 Respuestas
+ 9
No I can't, I've never heard of it...
+ 6
Umm, I think you may be referring to C/C++. Those are the only languages that I know implement assertions.
+ 4
You could think of assertion as "make sure this statement is true"
It can be used to prevent making operations over wrong data
+ 1
You need to understand the difference between assertion with try/except. Exceptions address the robustness of your application while assertions address its correctness.
Assertions should be used to check something that should never happen while an exception should be used to check something that might happen (something in which you don't have control like user input).
NOTE: The thumb rule is that use assertions when you are trying to catch your own errors and exceptions when trying to catch other people's errors.
0
simply to check if the code is doing as u expected. use it when u can't find the error by urself
0
An assertion is a sanity-check that you can turn on or turn off when you have finished testing the program.
An expression is tested, and if the result comes up false, an exception is raised.
Assertions are carried out through use of the assert statement.