assertions and _debug_ the assert statement can introduce debugging code into program the general form of assert is assert test [msgwhere test is an expression that should evaluate to true or false if test evaluates to falseassert raises an assertionerror exception with the optional message msg supplied to the assert statement here' an exampledef write_data(file,data)assert file"write_datafile not defined!the assert statement should not be used for code that must be executed to make the program correct because it won' be executed if python is run in optimized mode (specified with the - option to the interpreterin particularit' an error to use assert to check user input insteadassert statements are used to check things that should always be trueif one is violatedit represents bug in the programnot an error by the user for exampleif the function write_data()shown previouslywere intended for use by an end userthe assert statement should be replaced by conventional if statement and the desired error-handling in addition to assertpython provides the built-in read-only variable _debug_ _which is set to true unless the interpreter is running in optimized mode (specified with the - optionprograms can examine this variable as needed--possibly running extra error-checking procedures if set the underlying implementation of the _debug_ variable is optimized in the interpreter so that the extra control-flow logic of the if statement itself is not actually included if python is running in its normal modethe statements under the if _debug_ statement are just inlined into the program without the if statement itself in optimized modethe if _debug_ statement and all associated statements are completely removed from the program the use of assert and _debug_ allow for efficient dual-mode development of program for examplein debug modeyou can liberally instrument your code with assertions and debug checks to verify correct operation in optimized modeall of these extra checks get strippedresulting in no extra performance penalty lib fl ff