byte code if the - python command-line flag is usedthereby optimizing the program assertionerror is built-in exceptionand the __debug__ flag is built-in name that is automatically set to true unless the - flag is used use command line like python - main py to run in optimized mode and disable (and hence skipasserts exampletrapping constraints (but not errors!assertions are typically used to verify program conditions during development when displayedtheir error message text automatically includes source code line information and the value listed in the assert statement consider the file asserter pydef ( )assert ' must be negativereturn * python import asserter asserter ( traceback (most recent call last)file ""line in file \asserter py"line in assert ' must be negativeassertionerrorx must be negative it' important to keep in mind that assert is mostly intended for trapping user-defined constraintsnot for catching genuine programming errors because python traps programming errors itselfthere is usually no need to code assert to catch things like outof-bounds indexestype mismatchesand zero dividesdef reciprocal( )assert ! return generally useless assertpython checks for zero automatically such assert use cases are usually superfluous--because python raises exceptions on errors automaticallyyou might as well let it do the job for you as ruleyou don' need to do error checking explicitly in your own code of coursethere are exceptions for most rules--as suggested earlier in the bookif function has to perform long-running or unrecoverable actions before it reaches the place where an exception will be triggeredyou still might want to test for errors even in this casethoughbe careful not to make your tests overly specific or restrictiveor you will limit your code' utility for another example of common assert usagesee the abstract superclass example in therewe used assert to make calls to undefined methods fail with message it' rare but useful tool the assert statement