appendix exceptions to be true at given point in the program if the assertion failspython raises an assertionerror and aborts the programunless the exception is caught the assert statement combines the testing of condition with raising an exception the difference between making an assertion and raising an exception is that the assert statements can be deactivated at run time consider the min(function defined earlier rewritten to use the assert statementdef minarg arg )assert arg is not none and arg is not none"arguments to min(cannot be noneif arg arg return arg else return arg there are two forms of the assert statementthough both test the given condition and raise the assertionerror exception when the condition fails the difference is the inclusion of the optional descriptionwhich provides information to the programmer as to the cause of the error assert value assert value " positive value is required exceptions should be raised in those instances where you expect errors may occur during execution that can be properly handled without aborting the program for examplewhen checking for valid user input or verifying successful network connection to serverthe program does not have to be aborted when the operation fails insteadyou can catch the exceptioninform the userand provide an alternate course of action this may not be the casehoweverwhen precondition fails due to logical error in the program for exampleif the programmer incorrectly attempts to access list element by supplying an out-of-range indexit may be impossible to recover from such an error in this casethe program should abort as the proper course of action thusassertions are best used for debugging program and testing preconditions while exceptions are best used to catch recoverable errors as we stated earlierassert statements can be deactivated at run time in the final product to prevent them from being executed since assertions are made to help debug and catch programming errorsonce you have fully tested the programwe would not expect these errors to occur by turning them offthe execution speed of the program can be improved in the final production environment in additionthe end user of the program will have little use for the debug information when implementing abstract data typesit' important that we ensure the proper execution of the various operations by verifying any stated preconditions the appropriate mechanism is to state assertions for the preconditions and allow the user of the adt to decide how they wish to handle the error in most casesthe appropriate step is to allow the program to abort thusin the textwe focus on stating assertions and omit further discussion of catching those exceptions