What is the use of python assert assertions
Today, I will talk to you about the use of python assert assertions, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.
Assertion declaration is a convenient way to debug a program.
1. Assertions can be regarded as debug tools, and the implementation of Python is also in line with this design concept. The execution of the assert statement depends on _ _ debug__, and the default value is True.
2. If _ _ debug__ is True, only the assert statement is executed.
Example
Assert can declare two expression at the same time, for example, assert expression1, expression2 is equivalent to
If _ _ debug__: if not expression1: raise AssertionError (expression2)
If you execute the script file with the-O parameter, _ _ debug__ is False.
After reading the above, do you have any further understanding of the use of python assert assertions? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.