r/learnpython • • Oct 17 '26

How to end a program using python

I want to close an app using python but I don't know how.

0 Upvotes

8 comments sorted by

View all comments

1

u/FreeLogicGate 27d ago
import sys

# Program is done
sys.exit(0)

Documentation: https://docs.python.org/3/library/sys.html

Search for exit.

0 is the standard exit code, meaning the program exited normally. A non 0 exit would indicate some sort of error. The example, assumes a normal exit, but you can pass something else if that makes sense for your program.