control structures and functions preconditions and postconditions can be specified using assert statementswhich have the syntaxassert boolean_expressionoptional_expression if the boolean_expression evaluates to false an assertionerror exception is raised if the optional optional_expression is givenit is used as the argument to the assertionerror exception--this is useful for providing error messages notethoughthat assertions are designed for developersnot end-users problems that occur in normal program use such as missing files or invalid command-line arguments should be handled by other meanssuch as providing an error or log message here are two new versions of the product(function both versions are equivalent in that they require that all the arguments passed to them are nonzeroand consider call with argument to be coding error def product(*args)pessimistic assert all(args)" argumentresult for arg in argsresult *arg return result def product(*args)optimistic result for arg in argsresult *arg assert result" argumentreturn result the "pessimisticversion on the left checks all the arguments (or up to the first argumenton every call the "optimisticversion on the right just checks the resultafter allif any argument was then the result will be if one of these product(functions is called with argument an assertionerror exception will be raisedand output similar to the following will be written to the error stream (sys stderrusually the console)traceback (most recent call last)file "program py"line in product( file "program py"line in product assert result" argumentassertionerror argument python automatically provides traceback that gives the filenamefunctionand line numberas well as the error message we specified once program is ready for public release (and of course passes all its tests and does not violate any assertions)what do we do about the assert statementswe can tell python not to execute assert statements--in effectto throw them away at runtime this can be done by running the program at the command line with the - optionfor examplepython - program py another approach is to set the pythonoptimize environment variable to if the docstrings are of