execute script when quit python code example Example 1: python exit program Click to copyimport sys sys.exit() Example 2: how to stop the program in python Click to copyimport sys sys.exit()