← Go Back

How to Exit a Script

Using the sys.exit() standard function.

import sys
sys.exit()
print("This line won't execute")

Optionally, an error code (usually 1) can be given as argument, or 0 if the program has not ended with any error (this is the default value).

# The script ended due to some error.
sys.exit(1)


sys


🐍 You might also find interesting: