+ 1
In Python, how assertion is a important thing?
i understand assertion is to check and raise a error if some step fails in the program or i will say if desired results is not produced. But the problem is the code will terminate at that point. instead if i use a if-else block to print the error, wouldn't that be better?
2 odpowiedzi
+ 2
Python's assert statement is term that tests a condition. ... But if the assert condition evaluates to false, it raises an AssertionError exception with an optional error message. The proper use of assertions is to inform developers about unrecoverable errors in a program.
Hope this helps..!
0
For example, we have a statement that must be provided when writing a program. In such cases, we can quickly find errors when there is an error by using the assert method. Thanks to this method in long and complex programs, we can immediately catch the error and correct it. Otherwise, we have to examine all our code thoroughly to debug it. We can easily disable it at any time. Let's say we used the if method; And we don't want the program to run faster and take up too much space. Then we will have to delete all our entries one by one, and while deleting them, there is a danger of accidentally deleting if else codes that we use for other purposes. That's why the assert method makes our job much easier in debugging.