How can I exit a Python script early, similar to using the die() command in PHP?

How can I exit a Python script early, similar to using the die() command in PHP?

Hey Mattd,

Using sys.exit(): You can use the sys.exit() function from the sys module to exit the script. This function raises the SystemExit exception, which can be caught by the Python interpreter to exit the script.

import sys sys.exit()

Hey MattD,

Using os._exit(): The os._exit() function from the os module can be used to exit the script without calling cleanup handlers, flushing stdio buffers, or raising SystemExit.

import os os._exit(0)