← Go Back
Optionally, an error code (usually
How to Exit a Script
Using thesys.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)
🐍 You might also find interesting: