Interactive Site Helpers

exit — interactive site helper

exit is supplied by site for interactive shell use, not a dependable script API. Calling it raises SystemExit with the given code and may close standard input. Use sys.exit() in programs. It is normally absent when Python starts with -S.

Formal Syntax & Structure

python syntaxpython
exit(code=None)

Parameters & Attributes

NameTypeDescription
codeobjectRequested SystemExit argument; defaults to None.

Return Value

Never

Raises SystemExit instead of returning normally.

Working Example

Example Snippetpython
import subprocess, sysresult = subprocess.run([sys.executable, "-I", "-c", "exit(7)"], capture_output=True)print(result.returncode)
Python Reference